Using the formulas given below, write a program that:
1. Prompts the user for the size (N) of the data set.
2. Creates an array to store values of the data set.
3. Prompts the user to enter the values of the data set.
4. Receive and save data entered by the user.
5. Display the mean, variance, and standard deviation (sd) of the data set received.
Mean (x–) =(x1 + x2 +......+ XN)/N
Variance =(x1 - x–)² +(x2 - x–) + ..... + (XN - x–)²/N
sd=√variance
Note:
1. You are at liberty to decide what your program should look like when executed. Just ensure the steps above are followed and your grammar and formatting are sound.
2. Solve manually with the data set entered to confirm your program output.
#include <stdio.h>
#include <math.h>
int main()
{
int n;
printf("\nEnter the size of the dataset: ");
scanf("%d",&n);
int dataset[n];
printf("\nEnter the values of the dataset:\n");
for(int i=0;i<n;i++){
scanf("%d",&dataset[i]);
}
int sum=0;
for(int i=0;i<n;i++){
sum+=dataset[i];
}
int mean=sum/n;
printf("Mean = %d",mean);
int var=0;
for(int i=0;i<n;i++){
var+=pow((dataset[i]-mean),2);
}
double variance=var/(double)n;
printf("\nVariance = %.2lf ",variance);
double std;
std=sqrt(variance);
printf("\nStandard deviation = %.2lf",std);
return 0;
}
Comments
Leave a comment