Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. double std_dev( double a [], int x );
  6. const int MAX= 100;
  7.  
  8. int main ()
  9. {
  10. double next;
  11. int index = 0;
  12. double a[MAX];
  13.  
  14. cout << "I will give you the std deviation of a group of numbers less than "<< MAX << endl;
  15. cin >> next;
  16. while ((cin>>next) && (index < MAX))
  17. {
  18. a[index] = next;
  19. index++;
  20. cin >> next;
  21. }
  22. std_dev ( a , index );
  23. }
  24. double std_dev( double a [], int x )
  25. {
  26. double average, y;
  27. double sum = 0;
  28. int i;
  29. for( i = 0; i < x;i++ )
  30. {
  31. sum = sum + a[i];
  32. }
  33. average = sum / x;
  34. sum = 0;
  35. for( i = 0; i < x; i++ )
  36. {
  37. y =pow((a[i]-average),2);
  38. //cout << s<<" ";
  39. sum = sum + y;
  40. }
  41. cout <<(sqrt (sum / x));
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement