C Program to Add n Integers without Array
/* c program to add n integers without 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; 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); sum = sum + value; //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 )