#include <stdio.h>
#include <math.h>
void main()
{
float x[10];
int i, n;
float avrg, var, SD, sum=0, sum1=0;
printf(“Enter how many elements\n”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
scanf(“%f”, &x[i]);
}
/* Compute the sum of all elements */
for(i=0; i<n; i++)
{
sum = sum + x[i];
}
avrg = sum /(float) n;
/* Compute variance and standard deviation */
for(i=0; i<n; i++)
{
sum1 = sum1 + pow((x[i] – avrg),2);
}
var = sum1 / (float) n;
SD = sqrt(var);
printf(“Average of all elements =%.2f\n”, avrg);
printf(“Variance of all elements =%.2f\n”, avrg);
printf(“Standard deviation of all elements =%.2f\n”, SD);
}
/*—————————————————-
Output
Enter how many elements
5
10
21
32
59
17
Average of all elements =27.80
Variance of all elements =27.80
Standard deviation of all elements =17.15
——————————————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to input real numbers and find the mean, variance and standard deviation
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
- C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and and the computed sum with suitable heading
- C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
