Write a C++ programming to add repeatedly all digits of a given non-negative number until the result has only one digit
- برمجة سي بلس بلس
- برمجة
- 2021-05-13
- MarwaMohammed
الأجوبة
#include <iostream>
using namespace std;
int addDigits(int num) {
return num - (num - 1) / 9 * 9;
}
int main(void)
{
int n = 15;
cout << "\nInitial number is "<< n << " single digit number is " << addDigits(n) << endl;
n = 57;
cout << "\nInitial number is "<< n << " single digit number is " << addDigits(n) << endl;
return 0;
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال