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
|
#include <iostream>
#include <iomanip>
using namespace std;
void mode( int [], int );
int main (){
const int arraySize = 100;
int a[ arraySize ] = { 6, 7, 8, 9, 8, 7, 8,
7, 8, 9, 5, 9, 8, 7, 8,
6, 7, 8, 9, 3, 9, 8, 7,
7, 8, 9, 8, 9, 8, 9, 7,
6, 7, 8, 7, 8, 7, 9, 8,
7, 8, 9, 8, 9, 8, 9, 7,
5, 6, 7, 2, 5, 3, 9, 4,
7, 8, 9, 6, 8, 7, 8, 9,
7, 4, 4, 2, 5, 3, 8, 7,
4, 5, 6, 1, 6, 5, 7, 8,
9, 8, 9, 7, 1, 1, 7, 1,
9, 9, 2, 5, 3, 6, 4, 7,
1, 5, 6, 7, 9};
mode (a, arraySize );
}
void mode(int a[], int asize ){
int g = 0;
int count[9] = { 0 };
for (int f = 0; f < 9; ++f){
for (int j = 0; j < asize; ++j){
for (int i = 0; i < asize; ++i){
if (a[j] == a[i]){
g++;
count[f] = g;
}
}
}
}
for (int k = 0; k < 9; ++k){
if ( k % 10 == 0){
cout << "\n";
}
cout <<setw(7) << count[k];
}
}
|