C Programming Tutorial

Advertisements

Write program to display the sum of all elements in array in c



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int arr[5]; 
              int i,sum=0;
              clrscr();

              for(i=0;i<5;i++)
              {
                 printf("Enter any number : "); 
                 scanf("%d",&arr[i]); 
              }
              
              for(i=0;i<5;i++)
              sum = sum + arr[i];
              
              printf("\nThe sum of all elements in array : %d",arr[i]); 

              getch();              
       }
       
   Output : 

              Enter any number : 78 
              Enter any number : 45 
              Enter any number : 63 
              Enter any number : 82 
              Enter any number : 56 
              
              The sum of all elements in array : 9167




Advertisement