Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Rus");
- bool isNotCorrect = false;
- int num, res=0;
- do {
- cout << "Введите натуральное число\n";
- cin >> num;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные введены неккоректно\n\n";
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- while (num >= 10) {
- res = num % 10 + res;
- num = num / 10;
- }
- cout << "Сумма цифр данного числа " << res << endl;
- }
- } while (isNotCorrect);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement