0% found this document useful (0 votes)
44 views2 pages

Average and Standard Deviation of N Numbers

This document contains code to calculate the average and standard deviation of an unknown number of values entered by the user. The code uses a for loop to input values into an array until -100 is entered. It then calculates the sum and number of entries. The average is the sum divided by the number of entries. Another for loop calculates the sum of squared deviations from the average to get the variance, which is divided by the number of entries. The square root of the variance gives the standard deviation. The average and standard deviation are printed at the end.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Average and Standard Deviation of N Numbers

This document contains code to calculate the average and standard deviation of an unknown number of values entered by the user. The code uses a for loop to input values into an array until -100 is entered. It then calculates the sum and number of entries. The average is the sum divided by the number of entries. Another for loop calculates the sum of squared deviations from the average to get the variance, which is divided by the number of entries. The square root of the variance gives the standard deviation. The average and standard deviation are printed at the end.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

AVERAGE AND STANDARD DEVIATION OF N NUMBERS ( N IS NOT PREDETERMINED )

. PROGRAM/CODE: #include<stdio.h> #include<conio.h> #include<math.h> main() { int i,n; float a[100],sum,mean,ssd,var,sd; printf("Finding Mean and Standard Deviation of Given numbers\n"); printf("\nEnter numbers (After Entering all the values Enter -100):"); for(i=1;;i++) { scanf("%f",&a[i]); if(a[i]==-100) break; } sum=0; for(i=1;;i++) { if(a[i]==-100) break; sum=sum+a[i]; n=i; } printf(" Sum = %f \n n = %d",sum,n); mean=sum/n; ssd=0;

//ssd=sum of square of deviation// for(i=1;;i++) { if(a[i]==-100) break; ssd=ssd+((a[i]-mean)*(a[i]-mean)); } var=ssd/n; sd=sqrt(var); printf("\n Mean = %0.3f \n Standard Deviation = %0.3f ",mean,sd); getch(); }

You might also like