Write a C++ Program to Calculate Standard Deviation

C++ Program to Calculate Standard Deviation 

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Calculate Standard Deviation 
C++ Program to Calculate Standard Deviation

Write a C++ Program to Calculate Standard Deviation

PROGRAM:C++ Program to Calculate Standard Deviation

/* C++ Program to Calculate Standard Deviation*/

#include <iostream>
#include <cmath>
using namespace std;

float calculateSD(float data[]);

int main() {
int i;
float data[10];

cout << “Enter 10 elements: “;
for(i = 0; i < 10; ++i) {
cin >> data[i];
}

cout << endl << “Standard Deviation = ” << calculateSD(data);

return 0;
}

float calculateSD(float data[]) {
float sum = 0.0, mean, standardDeviation = 0.0;
int i;

for(i = 0; i < 10; ++i) {
sum += data[i];
}

mean = sum / 10;

for(i = 0; i < 10; ++i) {
standardDeviation += pow(data[i] – mean, 2);
}

return sqrt(standardDeviation / 10);
}

Leave a Reply

Your email address will not be published. Required fields are marked *