1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
// Example program
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int getInput (int N);
int N;
int sum = 0;
int i = 0;
double standarddev;
double difference;
int Average(int arr[], int N, int i);
int theMaximum (int arr[], int max, int i);
int theMinimum (int arr[], int min, int i, int N);
double stdDev (int N, int arr[], int average);
int theRange ( int max , int min);
int main()
{
int arr[N];
int max = 0;
int min;
int avg;
int thehighest;
int thelowest;
double stdDeviation;
getInput(N);
for ( int i=0; i < N;i++){
cin >> arr[i];
avg = Average(arr,N, i);
thehighest = theMaximum(arr, max, i);
min = arr[N-1];
thelowest = theMinimum (arr, min, i, N);
stdDeviation = stdDev (N, arr, avg);
}
stdDeviation = sqrt(stdDeviation);
cout << "The average is!"<< endl << avg << endl;
cout << "The max is!" << endl << thehighest << endl;
cout << "The Minimum is!" << endl << thelowest << endl;
cout << "The Standard Deviation is!" << stdDeviation << endl;
}
int getInput (int a){
cout << "How many numbers would you like in your set?" << endl;
cin >> N;
return (N);
}
int Average (int arr[], int N, int i){
int average;
//cout << i << endl;
//cout << arr[i] << endl ;
//for (int i = 0; i < N ; i++){
sum = sum + arr[i];
//}
//cout << sum << endl ;
average = sum/N;
//cout << average << endl;;
return average;
}
int theMaximum (int arr[], int max, int i){
if (arr[i] > max){
max = arr[i];
}
return max;
}
int theMinimum (int arr[], int min, int i, int N){
for (i= 0; i < N ; i++){
if (arr[i] < min){
min = arr[i];
}
}
return min;
}
double stdDev (int N, int arr[], int average){
int totaldiff = 0;
for( int i = 0; i < N; i++){
difference = (arr[i] - average)*(arr[i] - average);
totaldiff += difference;
standarddev = totaldiff/N;
}
return standarddev;
}
int theRange ( int max , int min){
int range;
range = max + min;
return range;
}
|