Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- void FillArray(int testArray[][9], int row);
- void ShowArray(int testArray[][9], int row);
- int HowMany(int testArray[][9], int number);
- int main()
- {
- int testArray[10][9];
- int userInput, occurance;
- FillArray(testArray,10);
- ShowArray(testArray,10);
- cout << "Enter the number you would like to find: ";
- cin >> userInput;
- occurance = HowMany(testArray, userInput);
- if(userInput > 0)
- {
- cout << "Number of occurrences: " << occurance << endl;
- }
- else
- {
- cout << "No number 0 or below can exist " << endl;
- }
- return 0;
- }
- int HowMany(int testArray[][9], int number)
- {
- int occuranceOfNumber = 0;
- for(int counter = 0; counter < 10; counter++)
- {
- for(int counter2 = 0; counter2 < 9; counter2++)
- {
- if(testArray[counter][counter2] == number)
- {
- occuranceOfNumber++;
- cout << "row: " << counter << "\t"<< " column: " << counter2 << " contains the number " << number << endl;
- }
- }
- }
- return occuranceOfNumber;
- }
- void ShowArray(int testArray[][9], int row)
- {
- for(int row = 0; row < 10; row++)
- {
- for(int column = 0; column < 9; column++)
- {
- cout << testArray[row][column] << "\t";
- }
- }
- }
- void FillArray(int testArray[][9], int row)
- {
- srand((unsigned)time(0));
- for(int counter = 0; counter < row; counter++)
- {
- for(int counter2 = 0; counter2 < 9; counter2++)
- {
- testArray[counter][counter2] = (rand() % 1000) + 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment