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
|
#include <iostream>
using namespace std;
int input(int ary[],const int m){//Input integers to array
int value;
cout<<"_ARRAY_RANGER_"<<endl<<"Enter 10 digits"<<endl;
for(int i=0;i<m;i++){
cout<<"Enter # (0-9)";
cin>>value;
if(value>10||value<0){
cout<<"ERROR"<<endl;
}
else{
ary[i]=value;//Input if condition works
}
}
}
int freq(int ary[],int freqary[],const int m){//Calculate frequency in array
for(int i=0;i<m;i++){
freqary[ary[i]]++;//Make a separate array for frequency
}
}
void data(int frqAry[],const int m){//List select data
int least=0;
int most=0;
int max=0;
int min=10;
for(int i=0;i<m;i++){//Number occurs x times
cout<<i<<" occurs "<<frqAry[i]<<" times."<<endl;
}
for(int i=0;i<m;i++){//Calculates number occured most
if(frqAry[i]>=max){
max=frqAry[i];
most=i;
}
}
cout<<most<<" occured the most."<<endl;
for(int i=0;i<m;i++){//Calculates number occured least
if(frqAry[i]<=min){
min=frqAry[i];
least=i;
}
}
cout<<least<<" occured the least."<<endl;
}
int Min(int ary[],const int m){//Minimum number input by user
int MIN;
MIN=ary[0];
for(int i=0;i<m;i++){
if(ary[i]<MIN){
MIN=ary[i];
}
}
return(MIN);
}
int Max(int ary[],const int m){//Max number input by user
int MAX;
MAX=ary[0];
for(int i=0;i<m;i++){
if(ary[i]>MAX){
MAX=ary[i];
}
}
return(MAX);
}
int main(){
int Min(int[],const int);
int Max(int[],const int);
int input(int[],const int);
int freq(int[],int[],const int);
void data(int[],const int m);
int MAX,MIN;
const int max=10;
const int yax=10;
int array[max];
int frqAry[yax];
input(array,max);
freq(array,frqAry,max);
data(frqAry,max);
MAX=Max(array,max);
cout<<"Maximum="<<MAX<<endl;
MIN=Min(array,max);
cout<<"Minimum="<<MIN<<endl;
}
|