Answer to Question #274437 in C for Asif

Question #274437

5. Write a C Program to calculate the Average of an array elements where the elements are


received as input.

1
Expert's answer
2021-12-03T12:37:03-0500


#include <stdio.h>
int main()
{
	int n,i;
	float numbers[100];
	float sum=0;
	float average=0;
	printf("Enter the number of elements: ");
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		printf("Enter number %d: ", (i+1));
		scanf("%f", &numbers[i]);
	}
	for (i = 0 ; i <n; i++)
	{
		sum+=numbers[i];
	}
	average=sum/(float)n;
	printf("The average of an array elements %.2f\n", average);


	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS