Home / Programs / C Program to Calculate Addition of All Elements in Array
🚀 Programming Example

C Program to Calculate Addition of All Elements in Array

👁 1,443 Views
💻 Practical Program
📘 Step Learning
C Program to Calculate Addition of All Elements in Array

💻 Program Code

/* 
C Program to Calculate Addition of All Elements in Array
Author: Atnyla Developer

*/

#include<stdio.h>
 
int main() {
   int i, arr[50], sum, num;
 
   printf("\nEnter no of elements :");
   scanf("%d", &num);
 
   //Reading values into Array
   printf("\nEnter the values :");
   for (i = 0; i < num; i++)
      scanf("%d", &arr[i]);
 
   //Computation of total
   sum = 0;
   for (i = 0; i < num; i++)
      sum = sum + arr[i];
 
   //Printing of all elements of array
   for (i = 0; i < num; i++)
      printf("\na[%d]=%d", i, arr[i]);
 
   //Printing of total
   printf("\nSum=%d", sum);
 
   return (0);
}
                        

🖥 Program Output


Enter no of elements :5

Enter the values :5
4
3
2
1

a[0]=5
a[1]=4
a[2]=3
a[3]=2
a[4]=1
Sum=15 
                            

📘 Explanation

C Program to Calculate Addition of All Elements in Array
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.