Write a program to Calculate the Mean of the array.
Mean: It is defined as the sum of terms divisible by the number of terms.
Formula: Sum of terms/number of terms
Example:
Input: arr[]={4,5,3,2,6,7} Output: Mean of array is 4.500000
C Program
#include <stdio.h>int main(){int arr[] = {4, 5, 3, 2, 6, 7};//find the lenth of arrayint n = sizeof(arr) / sizeof(arr[0]);int sum = 0;//find sum of arrayfor (int i = 0; i < n; i++){sum = sum + arr[i];}float mean = (float)sum / n;printf("Mean of array is %f", mean);}
No comments:
Post a Comment