Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

2 Aug 2012

C Program to Add n Integers without Array


/* 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