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

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf