Question

(Q2) Calculating the Distribution of Values 10 marks For a set of n real numbers {xi,..., x.J, here are a number of basic sta

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C code:

#include <stdio.h>

#include <math.h>

int main()

{

int n,i;

scanf("%d", &n); //read input n

  

float data[n]; //array of size n, to store data

for( i=0; i < n; i++) //to read n number of inputs

{

scanf("%f", &data[i]);

}

  

//minimum value

float minValue = data[0]; //initial assumption

for( i=1; i<n; i++)

{

if (minValue > data[i])

{  

minValue = data[i]; // update with minimum value

}

}

printf("The Minimum value m = %.6f \n", minValue );

  

//maximum value

float maxValue = data[0]; //initial assumption

for( i=1; i<n; i++)

{

if (maxValue < data[i])

{  

maxValue = data[i]; // update with maximum value

}

}   

printf("The Maximum value M = %.6f \n", maxValue );

  

//average

float sum = 0.0, avg;

for(i=0; i<n; i++)

{

sum += data[i]; //sum of all numbers

}

avg = sum/n; //average

printf("The Average value a = %.6f \n", avg );

//Standard Deviation

float sumSquares = 0.0, standardDeviation;

for(i=0; i<n; i++)

{

sumSquares += pow(data[i] - avg, 2); //sum of squares of difference of numbers from average

}

standardDeviation = sqrt(sumSquares/n);

printf("The Standard Deviation s = %.6f \n", standardDeviation);

return 0;

}

Code Screenshot :

CODE OUTPUT | |#1nclude<stdio.h> | #include<math.h> 4 int main int n,i; 7 | scanf(%d. &n); //read input n 9 float data[n):/

Output :

CODE OUTPUT The Minimum value m= 1.000000 The Maximum value M = 10.000000 The Average value a = 5.500000 The Standard Deviati

Add a comment
Know the answer?
Add Answer to:
(Q2) Calculating the Distribution of Values 10 marks For a set of n real numbers {xi,...,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT