PPS Practical 35

PPS Practical 35
  • Aim: Write a C program to calculate the average, geometric and harmonic mean of n elements in an array.
  • Code:
    //For turbo C++ remove below comments
    #include <stdio.h>
    //#include<conio.h>
    #include <math.h>
    void main()
    {
        int n,i;
        float arr[99],sum=0,g=1,h=0;
        //clrscr();
        printf("Enter length array : ");
        scanf("%d",&n);
        printf("Enter elements for array: \n");
        for (i = 0; i < n; i++){
            scanf("%f",&arr[i]);
            sum+=arr[i];
            g*=arr[i];
            h+=1.0/arr[i];
        }
        printf("Mean : %f\nGeometric Mean : %f\nHarmonic Mean : %f",sum/n,pow(g,1.0/n),n/h);
        // getch();
    }
  • Output:
    Output of practical 35

Comments