elements of the array c programming language - C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Friday, June 9, 2017

elements of the array c programming language

Array elements depend on the size of the array. An array size as much as the arrays of element.We used array in a program when we want to work with multiple variable and they have similar data type. Array every element work like an individual variable. For example,
                                                                         

Int first[10];

Here we declare an array that’s name ‘first’ and the subscript of the array 10, that’s means this array has 10 elements. Elements of the array are, first[0], first[1], first[2], first[3], first[4], first[5], first[6], first[6], first[7], first[8], first[9].

first[0] - first element index 0

first[1] – second element index 1

first[2] – third element index 2

first[3] – fourth element index 3

first[4] – fifth element index 4

first[5] – sixth element index 5

……………………………………………..

……………………………………………...

First[9]- tenth element index 9

Like this a array size as much as the arrays of element, and every element used through his index. Such as third element index two. Every element of the array takes 2 bytes, here we used 10 elements that’s means 10 elements takes 20 bytes. For example,

#include<stdio.h>

#include<conio.h>

int main()

{

int grade[10],i,sum=0;

float average;

clrscr();

for(i=0; i<10;i++)

{

printf("\n Enter grade %d : ",i+1);

scanf("%d",&grade[i]);

sum=sum+grade[i];



}

average= (float)(sum)/10;

printf("\n average is %f", average);

getch();

return 0;

}

In this program grade variable has 10 elements they are all of integer type array. So when we run this program then it will takes 20 bytes from the memory.





No comments:

Post a Comment