Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i = 0, j = 0, counter = 0, prev = 0, maxChar = 0;
- char yourCharacter;
- char arr[SIZE2][SIZE2]{
- { 'a', 'b', 'c', 'd', 'e' },
- { 'a', 'b', 'c', 'd', 'e' },
- { 'b', 'b', 'c', 'd', 'e' },
- { 'b', 'b', 'c', 'd', 'e' },
- { 'b', 'c', 'd', 'e', 'f' } };
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE2; j++)
- cout << arr[i][j];
- cout << endl;
- }
- cout << "please enter one character that you want ---> ";
- cin >> yourCharacter;
- for (i = 0; i < SIZE2; i++)
- {
- counter = 0;
- for (j = 0; j < SIZE2; j++)
- {
- if (arr[j][i] == yourCharacter)
- {
- counter++;
- }
- }
- if (counter > prev)
- {
- prev = counter;
- maxChar = i;
- }
- }
- if (prev > 0)
- {
- cout << endl << "The char " << yourCharacter << " appears: " << prev << " times in the matrix, in col: " << maxChar + 1 << endl;
- }
- else
- {
- cout << endl << "Sorry! the char " << yourCharacter << "] does not appear in the matrix" << endl;
- }
- break;
- system("pause");
- system("cls");
Advertisement
Add Comment
Please, Sign In to add comment