djelad1

Untitled

Nov 30th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. int i = 0, j = 0, counter = 0, prev = 0, maxChar = 0;
  2. char yourCharacter;
  3. char arr[SIZE2][SIZE2]{
  4. { 'a', 'b', 'c', 'd', 'e' },
  5. { 'a', 'b', 'c', 'd', 'e' },
  6. { 'b', 'b', 'c', 'd', 'e' },
  7. { 'b', 'b', 'c', 'd', 'e' },
  8.  
  9. { 'b', 'c', 'd', 'e', 'f' } };
  10. for (i = 0; i < SIZE2; i++)
  11. {
  12. for (j = 0; j < SIZE2; j++)
  13. cout << arr[i][j];
  14. cout << endl;
  15. }
  16.  
  17. cout << "please enter one character that you want ---> ";
  18. cin >> yourCharacter;
  19. for (i = 0; i < SIZE2; i++)
  20. {
  21. counter = 0;
  22. for (j = 0; j < SIZE2; j++)
  23. {
  24. if (arr[j][i] == yourCharacter)
  25. {
  26. counter++;
  27. }
  28. }
  29. if (counter > prev)
  30. {
  31. prev = counter;
  32. maxChar = i;
  33. }
  34. }
  35. if (prev > 0)
  36. {
  37. cout << endl << "The char " << yourCharacter << " appears: " << prev << " times in the matrix, in col: " << maxChar + 1 << endl;
  38. }
  39. else
  40. {
  41. cout << endl << "Sorry! the char " << yourCharacter << "] does not appear in the matrix" << endl;
  42. }
  43. break;
  44. system("pause");
  45. system("cls");
Advertisement
Add Comment
Please, Sign In to add comment