Write a program to find the repeated sum of digits of a number until it becomes a single-digit number in c++
Answers
Answered by
2
Answer:
sorry I know only Java..... ..........
Answered by
14
Answer:
#include<iostream>
using namespace std;
int p(int n)
{
int sum=0;
while(n>0||sum>9)
{
if(n==0){
n=sum;
sum=0;
}
sum=sum+n%10;
n=n/10;
}
return sum;
}
int main()
{
int n;
cin>>n;
cout<<p(n);
}
Explanation:
Similar questions