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 |
which is an algorithm for sorting in a growing Lexicographic order
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
How do we select the big element or any other operation from array which is read dynamically. user need to give the elements only no need to mention the size.
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?
what are the advantage and disadvantage of recursion
What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(“%d\n”,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview
2 Answers Satyam, UNIS, Wipro,
Is it possible to pass an entire structure to functions?
What is else if ladder?