Advertisement
Guest User

Количество чисел в строке

a guest
Oct 26th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.   string str;
  8.   cout << "Enter string:\n";
  9.   getline (cin, str);
  10.   int countOfNums = 0;
  11.   for (int i = 0; i < str.length(); i++) {
  12.       if (((int)str[i] >= (int)'0') && ((int)str[i] <= (int)'9')) {
  13.           countOfNums++;
  14.       }
  15.   }
  16.   cout << countOfNums << endl;
  17.   system("pause");
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement