1
0
Fork 0
Programming_Course1_Session2/17/Lab17/Lab17.cpp

32 lines
702 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int findFirstDigitIndex(string str) {
for (int i = 0; i < str.length(); i++) {
if (isdigit(str[i])) {
return i;
}
}
return -1;
}
int main() {
SetConsoleOutputCP(CP_UTF8);
string inputStr;
cout << "Введіть строку: ";
cin >> inputStr;
int index = findFirstDigitIndex(inputStr);
if (index >= 0) {
cout << "Індекс першої цифри в цій строчці: " << index << endl;
}
else {
cout << "У введеній строці не знайдено жодної цифри." << endl;
}
return 0;
}