Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <cmath>
- using namespace std;
- double std_dev( double a [], int x );
- const int MAX= 100;
- int main ()
- {
- double next;
- int index = 0;
- double a[MAX];
- cout << "I will give you the std deviation of a group of numbers less than "<< MAX << endl;
- cin >> next;
- while ((cin>>next) && (index < MAX))
- {
- a[index] = next;
- index++;
- cin >> next;
- }
- std_dev ( a , index );
- }
- double std_dev( double a [], int x )
- {
- double average, y;
- double sum = 0;
- int i;
- for( i = 0; i < x;i++ )
- {
- sum = sum + a[i];
- }
- average = sum / x;
- sum = 0;
- for( i = 0; i < x; i++ )
- {
- y =pow((a[i]-average),2);
- //cout << s<<" ";
- sum = sum + y;
- }
- cout <<(sqrt (sum / x));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement