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

What is volatile keyword in c?

587


Why c language is called c?

573


What are loops c?

616


What are the back slash character constants or escape sequence charactersavailable in c?

689


please send me the code for multiplying sparse matrix using c

1729






Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer

3846


What are header files and what are its uses in C programming?

640


Why do we use pointer to pointer in c?

601


the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....

22242


how to construct a simulator keeping the logical boolean gates in c

1732


Why doesnt long int work?

615


Are there namespaces in c?

570


What are the complete rules for header file searching?

678


Differentiate between the expression “++a” and “a++”?

709


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

746