Sum of array elements C program

It’s a sum of array elements C program that inputs numbers from the user, and stores these numbers in an array, then find the sum of all array elements using the loop, and print result on the screen.

To understand this program, it’s better you should know the following topics:

Program (1): to find sum and average of array elements.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,n,sum=0;
printf("Enter the number of elements(upto 100) to be entered in the list : ",n);
scanf("%d",&n);
//accepting values into array
for(i=0;i<n;i++)
{
printf("Enter %d element : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
sum=sum+a[i];
printf("sum=%d",sum);
getch();
}

Output (1)

Enter the number of elements(upto 100) to be entered in the list : 3
Enter 1 element : 12
Enter 2 element : 23
Enter 3 element : 1
sum=36

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *