/* Array: Suppose if we have to input 10 integer type of data then
10 separate integer variable have to declare before we use or input them.
But what will be the scene if the number of input increase upto 100 or 200
or more. The ARRAY reduces the complexity of the above problem.
An array is collection of similar types of data to be stored in memory and
which allows the different operations on the element of the array.
Array is stored in contiguous block of memory and it works on index.
Let see a simple program which implement declaration and input of array.
A program to input 10 integer types of data and to print the total. */
#include<stdio.h>
#include<conio.h>
void main()
{
int n[10],i=0,sum=0;
clrscr();
printf("Enter the elements of array: ");
for(i=0;i<10;i++) //loop to input 10 integers//
scanf("%d",&n[i]); //&n[i] means element is saved at (i)th position of the array
for(i=0;i<10;i++)
{
printf(" %d ",n[i]);
sum=sum+n[i];
}
printf("\nTotal is = %d ",sum);
getch();
}
No comments:
Post a Comment