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
|
//Mode.cpp
//##
#include <iostream>
using std::cout;
using std::endl;
bool isNotRepeated(int const key,int array[],int const SIZE,int position);
void printArray(int array[],int const SIZE);
int main(){
int const SIZE=10;
int setOfNumbers[SIZE]={0,5,3,0,5,6,7,7,8,0};
int ocurrences[SIZE]={}; //all of them start at 0 -zero-
//finding ocurrences
for(int i=0;i<SIZE;i++){
for(int j=0;j<SIZE;j++){
if(setOfNumbers[i]==setOfNumbers[j])
ocurrences[i]++;
}//end inner for
}//end outer for
//print array
cout<<"\nSet of numbers:\n";
printArray(setOfNumbers,SIZE);
cout<<endl;
cout<<"Ocurrences\n"<<endl;
for(int i=0;i<SIZE;i++){
if(ocurrences[i]>1&&isNotRepeated(setOfNumbers[i],setOfNumbers,SIZE,i))
cout<<"Number "<<setOfNumbers[i]<<" - "<<ocurrences[i]<<endl;
}//end for
return 0; //indicates success
}//end of main
bool isNotRepeated(int const key,int array[],int const SIZE,int position){
int counter=0;
for(int i=0;i<position;i++){
if(key==array[i])
++counter;
}//end for
if(counter>=1)
return false;
return true;
}//end function isNotRepeated
void printArray(int array[],int const SIZE){
for(int i=0;i<SIZE;i++){
cout<<array[i]<<((i+1)%5==0?'\n':' ');
}//end for
}//end function printArray
|