Skip to content

Instantly share code, notes, and snippets.

@jesuscmadrigal
Created October 10, 2017 15:29
Show Gist options
  • Save jesuscmadrigal/c324edd245fb2866003fe094750ff861 to your computer and use it in GitHub Desktop.
Save jesuscmadrigal/c324edd245fb2866003fe094750ff861 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
float total(float array[],int size){
float sum = 0.0;
for (int i=0;i<size;i++){
sum=sum+array[i];
}
return sum;
}
float average(float array[], int size){
float avg=total(array,size);
avg= avg/size;
return avg;
}
float derivation(float array[],int size){
float derivation = 0.0;
float avg = average(array,size);
for (int i=0;i<size;i++){
derivation=derivation+((array[i]-avg)*(array[i]-avg));
}
return derivation;
}
float standardderivation(float array[],int size){
float std;
std=sqrt((derivation(array,size))/size);
return std;
}
int main(){
float array [10];
for(int i=0;i<10;i++){
cout << "Please enter a number" << endl;
cin >> array[i];
}
cout << "the sum of those numbers is: " << total(array,10) << endl;
cout << "the standard derivation of those numbers is: " << standardderivation(array,10) << endl;
cout << "the average of those numbers is: " << average(array,10) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment