C Program to Add N integers using Array
/* C program to add n integers using array */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#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 )