Answer to Question #263886 in C for Kelly

Question #263886

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.

1
Expert's answer
2021-11-11T00:06:39-0500
#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;
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS