Useful programs in c programming language

C Programming Language/ programs

C program to shutdown a computer

#include <dos.h>
main()
{
system("c:\\windows\\system32\\shutdown /s /t 3600");  // means that it will go off after 3600 seconds
}

C Program To Calculate Mean and Standard Deviation


#include<math.h>                                                               
#include<stdio.h>                                                               
#define MAX 10                                                                  
                                                                                
void main()                                                                     
{                                                                               
 int i, n;                                                                      
 float num[MAX], deviation, sum, sumsqr, mean, variance, stddev;                
 sum = 0;                                                                       
 sumsqr =0;                                                                     
 n = 0;                                                                         
 printf("Enter number of elements:\n");                                         
 scanf("%d", &n);                                                               
                                                                                
 /* Reading array elements */                                                   
 printf("Input %d values \n", n);                                               
 for(i=0; i<n; i++)                                                             
 {                                                                              
  scanf("%f", &num[i]);                                                         
  sum += num[i];                                                                
 }                                                                              
 mean = sum/(float)n;                                                           
 printf("Mean is %f\n", mean);                                                  
 for(i=0;i<n;i++)                                                               
 {                                                                              
  deviation = num[i] - mean;                                                    
  sumsqr += deviation * deviation;                                              
 }           
 /* variance */                                                                   
 variance = sumsqr/(float)n;                                                    
 stddev = sqrt(variance);                                                       
 printf("Standard Deviation is %f\n", stddev);                                  
                                                                                
}  

OUTPUT:

Enter number of elements:
5
Input 5 values 
32
35
31
33
34
Mean is 33.000000
Standard Deviation is 1.414214

Comments

Popular posts from this blog

Exporting HTML Page into PDF In Django

C PROGRAMMING LANGUAGE