Given a number N, product(N) is the product of the digits of
N. We can then form a sequence N, product(N),
product(product(N))… For example, using 99, we get the
sequence 99, 99 = 81, 81 = 8.

Input Format:
A single integer N

Output Format:

A single integer which is the number of steps after which a
single digit number occurs in the sequence.

Sample Test Cases:

Input #00:
99

Output #00:
2

Explanation:
Step - 1 : 9 * 9 = 81
Step - 2 : 8 * 1 = 8
There are 2 steps to get to this single digit number.

Input #01:
1137638147

Answer Posted / vivekamr91

#include<stdio.h>
int main()
{
int s,sum;
long num;
printf("enter the no:");
scanf("%ld",&num);
sum=num;
while(sum>10)
{
sum=0;
while(num!=0)
{
s=num%10;
sum=sum+s;
num=num/10;
}
num=sum;
}
printf("the single digit sum is :%d",sum);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the difference between functions getch() and getche()?

608


What are the rules for the identifier?

671


What is meant by operator precedence?

678


What is a macro, and explain how do you use it?

628


Why is #define used?

790






Can we compile a program without main() function?

634


What is a program flowchart and explain how does it help in writing a program?

674


Explain how does flowchart help in writing a program?

631


Why clrscr is used after variable declaration?

1041


Tell us something about keyword 'auto'.

666


What is a 'null pointer assignment' error?

724


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

642


What are the preprocessor categories?

639


How would you obtain the current time and difference between two times?

728


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

665