C Program to the Summation of the Numbers in an Array

This program initializes an array ‘arr’ with some values, calculates the number of elements in the array, and then uses a loop to iterate through the array, adding each element to the sum variable. Finally, it prints the sum to the console. You can modify the values in the ‘aar’ array or use a different array to test the program with other sets of numbers.

Program :

#include<stdio.h>
int main()
{
int arr[100], size, i, sum = 0;
printf(“Enter array size\n”);
scanf(“%d”,&size);
printf(“Enter array elements\n”);
for(i = 0; i < size; i++)
scanf(“%d”,&arr[i]);
for(i = 0; i < size; i++)
sum = sum + arr[i];
printf(“Sum of the array = %d\n”,sum);
return 0;
}

Output :

Leave a Comment

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

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights
What do you like about this page?

0 / 400