/* C program to add n integers using array */
PROGRAM:
#include <stdio.h>
int main()
{
int n,i,value[100]; //declaring value as array whose length is 100
int sum=0; // declaring sum to zero , otherwise it stores garbage values
printf("\n Enter the number of integers you want to add: ");
scanf("%d", &n);
printf("\n Enter %d integers: ",n);
for (i = 1; i <= n; i++)
{
scanf("%d",&value[i]);
sum = sum + value[i]; //adding all entered integers to sum
}
printf("\n Sum of entered integers = %d \n",sum);
return 0;
}
Output: ( using GNU GCC Compiler with Code Blocks IDE )
No comments:
Post a Comment