Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

PROGRAM TO CALCULATE STANDARD DEVIATION

Posted By: Vid Fischer     Category: C Programming     Views: 24078

WRITE A PROGRAM TO CALCULATE STANDARD DEVIATION.

Code for PROGRAM TO CALCULATE STANDARD DEVIATION in C Programming

   #include <math.h>                                           
   #define   MAXSIZE    100                                    
                                                               
   main( )                                                     
   {                                                           
        int i,n;                                               
        floatvalue [MAXSIZE], deviation,                      
              sum,sumsqr,mean,variance,stddeviation;           
                                                               
        sum = sumsqr = n = 0 ;                                 
                                                               
        printf("Input values: input -1 to end \n");            
        for (i=1; i< MAXSIZE ; i++)                            
        {                                                      
            scanf("%f", &value[i]);                            
            if (value[i] == -1)                                
               break;                                          
            sum += value[i];                                   
            n += 1;                                            
        }                                                      
        mean = sum/(float)n;                                   
                                                               
        for (i = 1 ; i<= n; i++)                               
        {                                                      
            deviation = value[i] - mean;                       
            sumsqr += deviation * deviation;                   
        }                                                      
        variance = sumsqr/(float)n ;                           
        stddeviation = sqrt(variance) ;                        
                                                               
        printf("\nNumber of items : %d\n",n);                  
        printf("Mean : %f\n", mean);                           
        printf("Standard deviation : %f\n", stddeviation);     
   }                                                           
                                                               

   Output                                                      
                                                               
   Input values: input -1 to end                               
   65  9  27  78  12  20  33  49  -1                           
                                                               
   Number of items : 8                                         
   Mean : 36.625000                                            
   Standard deviation : 23.510303   
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO CALCULATE STANDARD DEVIATION Or get search suggestion and latest updates.

Vid Fischer
Vid Fischer author of PROGRAM TO CALCULATE STANDARD DEVIATION is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!