Multiply all the digits of a number n by each other, repeating with the product until a single digit is obtained. The number of steps required is known as the multiplicative persistence, and the final digit obtained is called the multiplicative digital root of n. For example, the sequence obtained from the starting number 9876 is (9876, 3024, 0), so 9876 has a multiplicative persistence of two and a multiplicative digital root of 0. Write a C Program to for finding number persistency and multiplicative root of any positive integer n.
CODE:
#include<stdio.h>
main()
{
int num=0,num1=0,num2=1,num3=0,num4=1;
printf("Enter no:");
scanf("%d",&num);
num1=num%10;
num2=num2*num1;
do{
num=(num-(num%10))/10;
num1=num%10;
if(num1>0)
{
num2=num2*num1;
}
else if(num==0)
{
printf("multiplicative persistence is:%d\n",num2);
}
}while(num!=0);
num3=num2%10;
num4=num4*num3;
do{
num2=(num2-(num2%10))/10;
num3=num2%10;
if(num2>0)
{
num4=num4*num3;
}
else if(num==0)
{
printf("multiplicative digital root is:%d",num4);
}
}while(num2!=0);
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment