Computer Science, asked by hania8711, 5 months ago

Write a programin c++ to calculate the average of n numbers & then compute the deviation of each number about the average.

Answers

Answered by mafattah
0

Answer:

#include <iostream>

#include <cmath>

int main() {

int n, i;

float num, sum = 0, avg, stdDev;

cout << "How many numbers?\n";

cin >> n;

i=1;

float numbs[n];

while(i<=n)

{

cout << "Enter the number " << i;

cin >> num;

sum = sum + num;

numbs[i]= num;

i++;

}

avg = sum/n;

cout << "\nSum = " << sum;

cout << "\nAverage = " << avg;

stdDev = getStandardDeviation(numbs, sum, n);

cout << "\nStandard Deviation= " << stdDev;

return(0);

}

float getStdDeviation(float numbs[], float sum, int n) {

float mean, SD = 0.0;

int i;

mean = sum / n;

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

SD += pow(numbs[i] - mean, 2);

return sqrt(SD / n);

}

Similar questions