Write a program to find the mean of the elements in the array.
Input Format:
Input consists of n+1 integers where n corresponds to the number of elements in the array.
The first integer corresponds to n and the next n integers correspond to the elements in the array. Assume that the maximum number of elements in the array is 20.
Output Format:
The output consists of a double value which corresponds to the mean of the array. It is printed upto 2 digits of precision.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to the input and the rest corresponds to output.]
Sample Input and Output :
Enter the number of elements in the array
5
Enter the elements in the array
2
4
1
3
5
The mean of the array is 3.00
Program Code:
#include<stdio.h>
int main()
{
int a[25],n,i;
float mean=0,sum=0;
printf("Enter the number of elements in the array\n");
scanf("%d",&n);
printf("Enter the elements in the array\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
sum=sum+a[i];
mean=sum/n;
printf("The mean of the array is %.2f",mean);
return 0;
}
Post A Comment:
0 comments: