How to Use Array Function


Arrays

Array is a group of same type of variables that have common name , each item in the group is called an element of the array. Each element is distinguished from another by an index, all elements are stored contiguously in memory. the elements of the array can be of any valid type such as integers, characters, floating point types or user designed types.

Array Declaration
Array are declared as other variables with the array size (total no of elements) enclosed in square brackets, For Example,
1.int x[100];
here , integer name 'x' with 100 elements.
2.char text[100];
here, text is character type with 100 elements.

Example:
Program to find sum and average of 10 integer number
#include<stdio.h>
#include<conio.h>
#define NUM 10
int main()
{
int grade[NUM],i,sum=0;
float avg;
printf("input scores:\n");
for(i=0;i<NUM;i++)
{scanf("%d",&grade[i]);
sum=sum+grade[i];
}
avg=(float)sum/NUM;
printf("Average=%f\n",avg);
getch();
}




Powered by Blogger.