Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <string.h>
- using namespace std;
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- char line[100];
- cout << "Введите строку: ";
- gets_s(line);
- char ch;
- cout << "Введите символ: ";
- cin >> ch;
- for (int i = strlen(line) - 1; i >= 0; i--) {
- if (line[i] == ch) {
- cout << i + 1 << " ";
- return 0;
- }
- }
- cout << "Нет такого символа" << endl;
- // второй вариант
- /*int i = strlen(line) - 1;
- for (; i >= 0; i--) {
- if (line[i] == ch) {
- cout << i + 1 << " ";
- break;
- }
- }
- if (i == -1) {
- cout << "Нет такого символа" << endl;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement