Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. void FillArray(int testArray[][9], int row);
  7. void ShowArray(int testArray[][9], int row);
  8. int HowMany(int testArray[][9], int number);
  9.  
  10.  
  11. int main()
  12. {
  13. int testArray[10][9];
  14. int userInput, occurance;
  15.  
  16. FillArray(testArray,10);
  17. ShowArray(testArray,10);
  18.  
  19. cout << "Enter the number you would like to find: ";
  20. cin >> userInput;
  21.  
  22. occurance = HowMany(testArray, userInput);
  23.  
  24. if(userInput > 0)
  25. {
  26. cout << "Number of occurrences: " << occurance << endl;
  27. }
  28. else
  29. {
  30. cout << "No number 0 or below can exist " << endl;
  31. }
  32.  
  33. return 0;
  34.  
  35. }
  36.  
  37. int HowMany(int testArray[][9], int number)
  38. {
  39. int occuranceOfNumber = 0;
  40.  
  41. for(int counter = 0; counter < 10; counter++)
  42. {
  43. for(int counter2 = 0; counter2 < 9; counter2++)
  44. {
  45. if(testArray[counter][counter2] == number)
  46. {
  47. occuranceOfNumber++;
  48. cout << "row: " << counter << "\t"<< " column: " << counter2 << " contains the number " << number << endl;
  49. }
  50. }
  51. }
  52. return occuranceOfNumber;
  53. }
  54.  
  55. void ShowArray(int testArray[][9], int row)
  56. {
  57. for(int row = 0; row < 10; row++)
  58. {
  59. for(int column = 0; column < 9; column++)
  60. {
  61. cout << testArray[row][column] << "\t";
  62. }
  63. }
  64. }
  65.  
  66. void FillArray(int testArray[][9], int row)
  67. {
  68. srand((unsigned)time(0));
  69.  
  70. for(int counter = 0; counter < row; counter++)
  71. {
  72. for(int counter2 = 0; counter2 < 9; counter2++)
  73. {
  74. testArray[counter][counter2] = (rand() % 1000) + 1;
  75. }
  76. }
  77. }
Add Comment
Please, Sign In to add comment