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
|
#include <iostream>
using namespace std;
int main()
{
// declare numbers array
int arrayNumbers[5][3] = {{1, 2, 7} , {2, 5, 3}, {1, 9, 4}, {2, 6, 5}, {7, 2, 2}};
// declare counter array
int searchFor[9]={1, 2, 3, 4, 5, 6, 7, 8, 9};
int timesOccured = 0;
int num = 0;
for (int row = 0; row < 5; row++)
for (int column = 0; column < 3; column++)
if (arrayNumbers[row][column] == searchFor[num])
{
timesOccured++;
num++;
}
else
num++;
cout << "The amount of " << searchFor[num] << "'s is: " << timesOccured << endl;
}
|