Programming assignment 2) Write a program that prompts the user for a variable n
ID: 3678087 • Letter: P
Question
Programming assignment 2) Write a program that prompts the user for a variable number of real numbers and 3) The specific descriptive statistics you should compute are: minimum, maximum, 4) Your program should adhere to the following IO specifications: computes several descriptive statistics on that set of real numbers. The real numbers should be placed in an array average and standard deviation. How many real numbers do you wish to enter (maximum is 20): Read number from user Enter number 1 Enter number 2 Repcat for all numbers> Minimum: ww.ww Maximum: xxxx Average: yy.yy Standard Deviation: z7.zz 5) When printing floating point values, only print the first 2 decimal placcs 6) This is a sample output of your program How many real numbers do you wish to enter (naximum is 20): 5 Enter number 1: 5.0 Enter number 2: 4.0 Enter number 3: 5. Enter nunber 4: 0.0 Enter nunber 5: 6. Mininun: 0.0 Maxinum: 6.00 Average: 4.88 Standard Deviation: 2.10Explanation / Answer
#include <stdio.h>
#include <math.h>
#define MAXSIZE 10
int main()
{
float x[MAXSIZE];
int i, n;
float average, variance, std_deviation, sum = 0, sum1 = 0;
printf("Enter the value of N ");
scanf("%d", &n);
printf("Enter %d real numbers ", n);
for (i = 0; i < n; i++)
{
scanf("%f", &x[i]);
}
float max = x[0];
float min = x[0];
/*
* Finds maximum and minimum in all array elements.
*/
for(i=0; i<n; i++)
{
/* If current element of array is greater than max */
if(x[i]>max)
{
max = x[i];
}
/* If current element of array is smaller than min */
if(x[i]<min)
{
min = x[i];
}
}
/* Compute the sum of all elements */
for (i = 0; i < n; i++)
{
sum = sum + x[i];
}
average = sum / (float)n;
/* Compute variance and standard deviation */
for (i = 0; i < n; i++)
{
sum1 = sum1 + pow((x[i] - average), 2);
}
variance = sum1 / (float)n;
std_deviation = sqrt(variance);
printf("min is= %.2f ",min);
printf("max is= %.2f ",max);
printf("Average of all elements = %.2f ", average);
printf("variance of all elements = %.2f ", variance);
printf("Standard deviation = %.2f ", std_deviation);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.