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
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / tuhin banerjee
#include<stdio.h>
int main()
{
int s,mul;
long num;
int count =0;
printf("enter the no:");
scanf("%ld",&num);
mul=num;
while(mul>10)
{
mul=1;
while(num!=0)
{
s=num%10;
mul=mul*s;
num=num/10;
}
num=mul;
count++;
}
printf("the single digit sum is :%d",mul);
printf("the single digit answer is :%d",count);
return 0;
}
Is This Answer Correct ? | 0 Yes | 2 No |
Why clrscr is used in c?
Write programs for String Reversal & Palindrome check
How to calculate sum
What is the purpose of the statement: strcat (S2, S1)?
Why header file is used in c?
What is structure padding in c?
Why do we use static in c?
wt is diference between int and int pointer as same as float and float pointer and char and char pointer
What is the difference between union and anonymous union?
Expand the following LKB BKL FFG
any "C" function by default returns an a) int value b) float value c) char value d) a & b
What's the difference between DELETE TABLE and TRUNCATE TABLE commands?