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 |
Is c++ based on c?
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
Write a C program to print 1 2 3 ... 100 without using loops?
Why C language is a procedural language?
What ios diff. Between %e & %f?
Explain how can I make sure that my program is the only one accessing a file?
Difference between MAC vs. IP Addressing
What does c mean before a date?
print 1-50 with two loop & two print Statement
in one file global variable int i; is declared as static. In another file it is extern int i=100; Is this valid ?
Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80