Program to Evaluate Standard Deviation by passing it to function in CPP (C plus plus)

Program to Evaluate Standard Deviation by passing it to function in CPP (C plus plus)

In this tutorial, we will learn about the Program to Evaluate Standard Deviation by passing it to function in CPP (C plus plus).

#include <iostream>
#include <cmath>

using namespace std;

float cal_SD(float data[]);

int main()
{
    float info[10];
	int k;
    
    cout<<"Please enter any 10 elements: ";
    
    for(k=0;k<10;++k)
        cin >> info[k];

    cout<<endl<<"Standard Deviation= "<<cal_SD(info);

    return 0;
}

float cal_SD(float data[])
{
    float mean;
	float add=0.0;
	float SD=0.0;

    int k;

    for(k=0; k<10; ++k)
    {
        add+= data[k];
    }

    mean = add/10;

    for(k=0; k<10; ++k)
        SD+= pow(data[k] - mean, 2);

    return sqrt(SD/10);
}

Output:

Program to Evaluate Standard Deviation by passing it to function in CPP (C plus plus)
Program to Evaluate Standard Deviation by passing it to function in CPP (C plus plus)
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.