English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The program should be in java....
Example-461 = 4*6*1 = 24 = 2*4 = 8
pls answer if you know.......i need the answer urgently!!!!
Thankyou!!!

2006-07-21 23:06:40 · 3 answers · asked by neha 1 in Computers & Internet Programming & Design

HI pinks if you know it in C or C++....can you pls write that for me!!!

2006-07-21 23:22:11 · update #1

3 answers

int main(void) {
unsigned int num = 0;
cin >> num; // get the number

unsigned int prod = 1;
while(true) {
// find the product of digits in num
while(num > 0) {
prod *= num%10; // extract last digit
num /= 10; // remove the last digit from the number
}
if( prod < 10) { // Is the product a single digit
break;
}
// else, intermediate prod is the new num
num = prod;
prod = 1; // intialize prod to 1
}
cout<< prod<< endl;

return 0;
}

2006-07-22 00:43:07 · answer #1 · answered by swami060 3 · 0 0

i dnt know java that much..u can use recursion..loop will calculate the product of any digit no. recursively until its a single digit..its very easy..i cud hv written it in c or c++ but that wont help u alot..or u can use a loop that does it..

2006-07-22 06:18:35 · answer #2 · answered by pinks 2 · 0 0

this will do in c ....put ur head to it then itll work in java

void main()
{
int crack(int,int);
int c,i;
scanf("%d",&c);

while(c/10!=0)
{
for(i=0;;i++)
{
if(c/pow10(i)<1.0)
break;
printf("\ni=%d",i);
printf("\t%f",c/pow10(i));
}
//now if i=0 then the input is 0

c=crack(c,i-1);
}
printf("%d",c);
}

int crack(int a,int j)
{
float b1;
int b;

if (j<0) return(1);
if (j==0) return(a);

b=a/pow10(j);
a=a-b*pow10(j);

return(b*crack(a,j-1));
}

2006-07-22 06:23:35 · answer #3 · answered by David 2 · 0 0

fedest.com, questions and answers