# Thread: while loop working out inverse of a factorial

1. ## while loop working out inverse of a factorial

hi all i have the following code:
Code:
```     int x, factorial;
double  value, inverse_factorial;

printf("Enter the smallest value of 1/n!: ");
scanf(" %lf", &value);

printf("value = %lf\n", value);
x = 2;
factorial = 1; //set to 1!
inverse_factorial = 1;
while (inverse_factorial > value)
{
factorial *= x; // 1!*2=2! 2!*3=3!......8!*9=9!
x++; //incriment multiplier
inverse_factorial = 1/factorial;
}
printf("x = %d\n", x);

return 0;```
the only value of x i ever get is 3 no matter how small i set value and i cant for the life of me see why

any suggestions greatly appreciated
coop

2. When both operands are integers, the result is an integer. If you want a double, either (or both) of them need to be double. Here, just use "1.0" instead of "1".

3. thanks.... annoying thing is it was ..........ing because i had scanf("%f", &value); i was getting a warning about putting a float into a double but answer = 1/factorial you get bugger all

Popular pages Recent additions