k) Find values greater than k, where k is entered by the user.
1
Expert's answer
2011-12-22T08:45:59-0500
#include <iostream> #include <cstdlib> #include <cmath> using namespace std;
int main(int argc, char* argv[]){ int const ARRAY_SIZE = 10; int data[ARRAY_SIZE];
int min,max,k; double avg = 0, std = 0; cout << "Created data: " << endl; for(int i = 0; i < ARRAY_SIZE; ++i){
data[i] = (int)rand(); // random data cout << data[i] << ' '; avg += data[i]; // sum of all elements } avg /= ARRAY_SIZE; // average cout << endl << "Average: " << avg << endl; min = data[0]; max = data[0];
for (int i = 1; i < ARRAY_SIZE; ++i){ if (data[i] > max) max = data[i]; // maximum if (data[i] < min) min = data[i]; // minimum } cout << "Maximum: " << max << endl; cout << "Minimum: " << min << endl; // standart deviation calculation begin for (int i = 0; i < ARRAY_SIZE; ++i){ std += pow((data[i] - avg),2.0); } std /= (ARRAY_SIZE - 1); std = sqrt(std); // end cout << "Standart devation: " << std << endl;
// even numbers cout << "Even numbers: "; for (int i = 0; i < ARRAY_SIZE; ++i){ if ((data[i] % 2) == 0) cout << data[i] << ' '; } // end
// odd numbers cout << endl << "Odd numbers: "; for (int i = 0; i < ARRAY_SIZE; ++i){ if ((data[i] % 2) != 0) cout << data[i] << ' '; } // ned
// prime numbers cout << endl << "Prime numbers: "; for (int i = 0; i < ARRAY_SIZE; ++i){ int j; for(j = 2; j <= (data[i] - 1); ++j){ if((data[i] % j) == 0) break; } if (j == data[i]) cout << data[i]; } // end
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment