Finding sum of digits of a number until sum becomes single digit
Answers
Answered by
0
ask to google this question
Answered by
2
Answer:
#include<iostream>
using namespace std;
int digSum(int n)
{
int sum = 0;
while(n > 0 || sum > 9)
{
if(n == 0)
{
n = sum;
sum = 0;
}
sum += n % 10;
n /= 10;
}
return sum;
}
int main()
{
int n;
cin>>n;
cout << digSum(n);
return 0;
}
Step-by-step explanation:
Similar questions