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
Write a Program to find whether the given number or string is palindrome.
Is fortran still used in 2018?
How can I read/write structures from/to data files?
What is the difference between typedef struct and struct?
What is the difference between formatted&unformatted i/o functions?
What is volatile c?
What are the different properties of variable number of arguments?
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
What does double pointer mean in c?
What is the use of a conditional inclusion statement in C?
How to declare a variable?
Why isnt there a numbered, multi-level break statement to break out
What are the benefits of c language?
What is the advantage of a random access file?
When can a far pointer be used?