Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- void fillArray(int a[], int size) {
- srand((int)time(0));
- for (int i = 0; i<size; i++)
- a[i] = (rand() % 100) + 1;
- }
- double getMean( int a[], int size) {
- int sum = 0;
- for (int i = 0; i<size; i++) {
- sum += a[i];
- }
- return sum/size;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- void getMode( int a[], int size) {
- int maxV = 0;
- int maxC=0;
- for (int i = 0; i<size; i++) {
- int c=0;
- for(int z =0;z<size;z++){
- if(a[z] == a[i]){
- c++;
- }
- }
- if(c-1> maxC){
- maxC=c;
- maxV=a[i];
- }
- }
- if(maxC == 0){
- cout << "****N/A There are no repeating numbers*****" <<endl ;
- }
- else{
- for (int i = 0; i < size; i++) {
- int count = 0;
- for (int j = 0; j < size; j++) {
- if (a[j] == a[i])
- count++;
- }
- if (count == maxC) {
- cout<< a[i]<<" ";
- }
- }
- }
- }
- //////////////////////////////////////////////////////////////////
- double getHighV( int a[], int size) {
- double maxxV=0;
- for(int i = 0;i<size;i++){
- if(a[i]>maxxV){
- maxxV=a[i];
- }
- }
- return maxxV;
- }
- double getLowV( int a[], int size) {
- double lowV=a[0];
- for(int i = 0;i<size;i++){
- if(a[i]<lowV){
- lowV=a[i];
- }
- }
- return lowV;
- }
- int main() {
- int ary[15];
- int size = 15;
- fillArray(ary, size);
- cout << "Random values: " << endl;
- for (int i = 0; i<15; i++){
- cout << ary[i]<<endl;
- }
- cout<< endl;
- cout << "Mean of the array: " << getMean(ary, size) << endl;
- cout << "Mode(s) of the array(modes will be displayed"<<endl;
- cout<< "the same number of times they appear in the array): ";
- getMode(ary, size);
- cout<< endl;
- cout << "Highest value of the array: "<< getHighV(ary, size) << endl;
- cout << "Lowest value of the array: "<< getLowV(ary, size) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement