Computer Science, asked by hiralalgautam6013, 9 days ago

Write a
program to accept element of size 5 and add 5 in each element. ​

Attachments:

Answers

Answered by ajith1987aug
0
#include

int main()
{
//let's assume the maximum array size as 5
//initialize sum as 0. Otherwise, it will take some garbage value.
int arr[5], size, i, sum = 0;

//Get size input from user
printf("Enter array size\n");
scanf("%d",&size);

//Get all elements using for loop and store it in array
printf("Enter array elements\n");
for(i = 0; i < size; i++)
scanf("%d",&arr[i]);

//add all elements to the variable sum.
for(i = 0; i < size; i++)
sum = sum + arr[i]; // same as sum += arr[i];

//print the result
printf("Sum of the array = %d\n",sum);

return 0;
}
Similar questions