Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>;
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int i, n = 2, count=0;//i-для цикла(позиция символа в строке) n-будет использоваться для обозначения размернотсти строки
- cout << "enter the letter ";
- char c = NULL;//перменная для ввода искомого символа
- cin >> c;
- cout << "enter the size of the string ";
- char* str = NULL;//переменная для ввода строки
- cin >> n;
- cout << "enter the string ";
- str = new char[n];//ввод строчного массива
- cin >> str;
- for (i = 0; str[i] !='\0'; i++) {
- count++;
- }
- cout << "number of the symbols in the string " << count<<endl;
- if (count > n)//проверка на превышение лимита символов в строке
- cout << "wrong enter,restart the programm " << endl;
- else
- {
- for (i = 0; i < n; i++) {//цикл для нахождения первого появления символа в строке и его номера
- if (str[i] == c)
- break;
- }
- if (str[i] == c)
- cout << "letter " << c << " appear on the position: " << i + 1 << endl;
- else if ((str[i] != c) && (i < n))
- cout << "not exist" << endl;
- }
- str = NULL;
- delete[] str;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement