C Program For Addition of All Elements of the Array

C Program For Addition of All Elements of the Array

#include<stdio.h>
int main()
{

   int i, arr[50], sum, num;

   printf("Enter no of elements :\n");
   scanf("%d", &num);


   printf("\nEnter the values :");
   for (i = 0; i < num; i++)
   {
      scanf("%d", &arr[i]);   //array read elements
   }
 
   sum = 0;
   for (i = 0; i < num; i++)
   {
      sum = sum + arr[i];  //sum of array element
   }
 
   for (i = 0; i < num; i++)
   {
    printf("\na[%d]=%d", i, arr[i]);  //print all element of array
   }
   

 
   printf("\nSum=%d", sum);  //print sum of array elements

}

Related Posts