162k views
0 votes
Write a C program to show sum of 10 elements of array and show the average.

1 Answer

5 votes

Answer:

// C program to find sum and average of 10 elements.

#include <stdio.h>

// main function

int main(void) {

// array

double arr[10];

// variables

double average,sum=0;

int i;

// ask to enter 10 elements of the array

printf("Enter 10 elements of the array:");

for(i=0;i<10;i++)

{

// read elements of the array

scanf("%lf", &arr[i]);

// calculate the sum of elements

sum=sum+arr[i];

}

// fint the average

average=sum/10;

// print sum

printf("Sum of 10 elements of the array is:%f ",sum);

// print average

printf("\\Average of 10 elements of the array is:%f ",average);

return 0;

}

Step-by-step explanation:

Create an array of size 10.Then read 10 values from user and store them into array.Find the sum of 10 elements of the array and assign it to variable "sum". Find the average by dividing sum with 10.Print the sum and average.

Output:

Enter 10 elements of the array:3 2 4 5 1 4 8 9 12 10

Sum of 10 elements of the array is:58.000000

Average of 10 elements of the array is:5.800000

User Ash Eldritch
by
4.9k points