Ребята можете по быстрому код из C++ делать для C ? #include <iostream> #include <string> using namespace std; int main() { string str; int s=0; cout <<"Строка:"; getline (cin,str); for (unsigned int i = 0 ; i<str.length();i++) { if (isdigit(str)) s++; } { cout <<"Количество цифр: "<<s<<endl; } return 0 ; } Спасибо за ранее,симпу и репку с меня)
вот так на шарпе оно будет работать Спойлер #include "pch.h" #include <ctype.h> #include <iostream> #include <string> #include <stdio.h> using namespace std; int main() { string str; int s = 0; cout << "Enter line:"; getline(cin, str); for (unsigned int i = 0; i < str.length(); i++) { if (isdigit(str[i])) s++; } cout << "Number of digits: " << s << endl; return 0; } Код #include "pch.h" #include <ctype.h> #include <iostream> #include <string> #include <stdio.h> using namespace std; int main() { string str; int s = 0; cout << "Enter line:"; getline(cin, str); for (unsigned int i = 0; i < str.length(); i++) { if (isdigit(str[i])) s++; } cout << "Number of digits: " << s << endl; return 0; }
заметил, сайт обрезает часть кода если не кидать его под "CODE" вот на C #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char str[255]; int s = 0; printf("Enter line:"); gets(str); int i; for (i = 0; i < sizeof(str); i++) { if (str[i] == '\0') { printf("Number of digits: %d\n", s); break; } if (isdigit(str[i])) s++; } return 0; } Код #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char str[255]; int s = 0; printf("Enter line:"); gets(str); int i; for (i = 0; i < sizeof(str); i++) { if (str[i] == '\0') { printf("Number of digits: %d\n", s); break; } if (isdigit(str[i])) s++; } return 0; }
Код #include <iostream> #include <string> using namespace std; int main() { string str; int s=0; cout <<"Строка:"; getline (cin,str); for (unsigned int i = 0 ; i<str.length();i++) { if (isdigit(str)) s++; } { cout <<"Количество цифр: "<<s<<endl; } return 0 ; }