Skip to main content

C Program to find Mean and Standard deviation(SD) for a set of n numbers using array.

 C Program to find Mean and Standard deviation(SD) for a set of n numbers using array.

    In this example, we will calculate the mean and standard deviation for a set of n numbers entered by the user using array. 

 

PROGRAM TO FIND THE MEAN AND STANDARD DEVIATION(SD) FOR A SET OF N NUMBERS USING ARRAY.

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
    int n,i;
    float x[50],mean,sd,sum;
    printf("How many numbers you want to enter : ");
    scanf("%d",&n);
    printf("Enter the numbers ");
    for(i=0;i<n;i++) 
    {
        scanf("%f",&x[i]);
    }
    for(i=0;i<n;i++)
    {
        sum+=x[i];
    }
    mean=sum/n;
    sum=0;
    for(i=0;i<n;i++)
    {
        sum=sum+(x[i]-mean)*(x[i]-mean);
    }
    sd=sqrt(sum/n);
    printf("Mean =%6.3f\n",mean);
    printf("Standard Deviation : %6.3f\n",sd);
    getch();
}


OUTPUT  TO FIND THE MEAN AND STANDARD DEVIATION(SD) FOR A SET OF N NUMBERS USING ARRAY.

 How many numbers you want to enter : 5

 Enter the numbers 23.3

 12

 45

 63

 5.5

 Mean =29.760

 Standard Deviation : 21.368


NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

You Learn, I Learn together We Learn.

Comments