Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,b,d;
- int sum = 0;
- int sum1 = 0;
- int c = 0;
- int number;
- cin >> number;
- while(number > 0)
- {
- a = number % 10;
- sum = sum + a;
- number = number / 10;
- }
- cout << sum << endl;
- if(sum > 9)
- {
- while(sum > 0)
- {
- b = sum % 10;
- c = c + b;
- sum = sum / 10;
- }
- }else{
- return 0;
- }
- cout << c << endl;
- if(c > 9)
- {
- while(c > 0)
- {
- d = c % 10;
- sum1 = sum1 + d;
- c = c / 10;
- }
- }else{
- return 0;
- }
- cout << sum1 << endl;
- }
- /*При дадено n вземете сумата от цифрите на n. Ако тази стойност има повече от една цифра, продължете да намалявате по този начин, докато получите едноцифрено число. Входът ще бъде неотрицателно цяло число.
- 16 --> 1 + 6 = 7
- 942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6
- 132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6
- 493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement