Headlines
Loading...
C program to find the arithmetic mean of n numbers

C program to find the arithmetic mean of n numbers

Write a function to find the arithmetic mean of n numbers. (pass an array

to a function).

Function prototype : float amean(flaot x[], int n)*/

 

#include<stdio.h>

#include<conio.h>

void main()

{

            float a[30],am;

            int n,i,j;

            float amean(float [],int);

            clrscr();

            printf("How Many Numbers For Arithmetic Mean==");

            scanf("%d",&n);

            printf("\nEnter %d Numbers\n",n);

            for(i=0;i<n;i++)

                        scanf("%f",&a[i]);

            am=amean(a,n);

            printf("\nArithmetic Mean of %d Numbers==%f",n,am);

getch();

}

float amean(float *a,int n)

{

            float am=0;

            int i;

            for(i=0;i<n;i++)

            {

                        am=am+*(a+i);

            }

            am=am/n;

            return am;

}

/* Output

How Many Numbers For Arithmetic Mean==6

 

Enter 6 Numbers

1

3

6

5

12

23

  

Arithmetic Mean of 6 Numbers==8.333333

*/
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***