Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

One-Dimensional Array-:

Declaration of 1-d Array-:
Before using an array in program,it is must to declare it,The syntax to declare 1-d array is as follow-:
Syntax-:
data type array name[size of array];
Example-:
          1-  int marks[5];
Each memory location will occupy 2 byte.
         2-  float temps[5];
Each memory location will occupy 4 byte.
          3-  char name[5];
name[0] name[1] name[2] name[3] name[4]
Each memory location will occupy 1 byte.
ads  
  Storage of Values in 1-d Array-:
In an array values can be stored by below two methods-:
  1. Initialization method.
  2. Input method.
Initialization Method-:
In this method values to be stored in an array are provided at the time,when the array is declared.If the values to be stored in array are known to programmer than this method is best to initialize array.
Syntax-: 
data type   array name[size of array]= {value 1,value 2,value 3,------value n};
Example-:
int num[5]={7,88,32,76,56};
float per[7]={3.4,5.9,4.8,2.6,7.2,6.1,5.8};
char name[10]="sudarshan";
  • While initializing an array it is optional to provide the size of array.In such as case, the size of array is determine by the number of value initialized.
  • If the number of values initialized are less than the size of array then the remaining location are automatically filled with zero.

Input Method-:
 When the values of array are stored at run-time,then the input method is used in 1-d array.
Syntax-: 
for(i=0;i<size of array;i++)
{printf("\n Enter array element format specifier",array name[i]);
  scanf("format specifier",array name[i]);
}
Example-:
for(i=0;i<10,i++)
{printf("\n Enter array element %d ",num[i]);
  scanf("%d",num[i]);
}
How to print value stored in 1-d Array?
The following syntax is used to print value stored in 1-d array-:
Syntax-: 
printf("Array element are:\n);
for(i=0;i<size of array;i++)
printf("format specifier",array name[i]);
Example-:
printf("Array element are:\n);
for(i=0;i<10;i++)
printf("%d \n",num[i]);
Q- Write a program to insert marks of five student in one dimensional array.
#include <stdio.h>
int main()
{
int s[5] = {77, 76, 78, 91,74}, i;
printf("\nStudents marks details:-");
for(i = 0; i < 5; i++)
{
printf("\ns%d = %d ", i + 1, s[i]);
}
return 0;
}
Output-:
Students marks details:-
s1 = 77
s2 = 76
s3 = 78
s4 = 91
s5 = 74
  Introduction Of Array CLICK HERE
Watch The Below  Videos






Comments

  1. defination and intro of array...go to below url
    https://techprogramiz.blogspot.com/2020/05/array.html

    ReplyDelete

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey