Skip to main content

Sum, Average and Standard deviation in c

 Sum, Average and Standard deviation


Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ).


#include<stdio.h>

void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std)

void main()

{
clrscr();
float ave,sd;
int a,b,c,d,e,sum;
printf("\nInput 5 integers\n");
scanf("\n%d\n%d\n%d\n%d\n%d",&a,&b,&c,&d,&e); 
stat(a,b,c,d,e,&sum,&ave,&sd);
printf("\nThe sum is %d\nThe average is %f\nThe standard deviation is %f",sum,ave,sd);
}


void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std)

{
*su=a+b+c+d+e;
*av=*su/5;
*std=sqrt(((((a-*av)*(a-*av))+((b-*av)*(b-*av))+((c-*av)*(c-*av)))/5.0);
}


Comments

Popular posts from this blog

Convert numbers to roman numerals

Convert numbers to roman numerals       #include <stdio.h> #include <conio.h> void predigits (char c1,char c2); void postdigits (char c,int n); char roman_Number[1000]; int i=0; int main() {     int j;     long int number;        printf( "Enter any natural number: " );     scanf( "%d" ,&number);        if (number <= 0) {          printf("Invalid number");          return 0;     }     while (number != 0){          if (number >= 1000){              postdigits('M',number/1000);              number = number - (number/1000) * 1000;          } ...

To Create Triangle and Structure

 To Create Triangle and Structure   C Program To display the triangle using *, numbers and character Write a C Program to print half pyramid as using * as shown in figure below. * * * * * * * * * * * * * * * #include <stdio.h> int main () { int i , j , rows ; printf ( "Enter the number of rows: " ); scanf ( "%d" ,& rows ); for ( i = 1 ; i <= rows ; ++ i ) { for ( j = 1 ; j <= i ; ++ j ) { printf ( "* " ); } printf ( "\n" ); } return 0 ; }     Write a C Program to print half pyramid as using numbers as shown in figure below. 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5   #include <stdio.h> int main () { int i , j , rows ; printf ( "Enter the number of rows: " ); scanf ( "%d" ,& rows ); for ( i = 1 ; i <= rows ; ++ i ) { for ( j = 1 ...