Calculate Mean of the array

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[] = {453267};

    //find the lenth of array
    int n = sizeof(arr) / sizeof(arr[0]);

    int sum = 0;

    //find sum of array
    for (int i = 0i < ni++)
    {
        sum = sum + arr[i];
    }
    float mean = (float)sum / n;
    printf("Mean of array is %f"mean);
}


No comments:

Post a Comment