Multiply all of the digits of N, and repeat the same with the product obtained till the product consists of only one digit. Output the number of steps taken to do so. code example
Example: To add all the digits of a number till you get a single digit.
#include<bits/stdc++.h>
using namespace std;
int digSum(int n)
{
if (n == 0)
return 0;
return (n % 9 == 0) ? 9 : (n % 9);
}
int main()
{
int n = 9999;
cout<<digSum(n);
return 0;
}