/* c program to add n integers without using array */
PROGRAM:
#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 )
No comments:
Post a Comment