Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //a program that approximate e by computing values
- #include <stdio.h>
- int main(void)
- {
- //initialise variables for use
- float num, result=2;
- //scan for the number
- scanf("%f", &num);
- //factorial method
- float factorial(int n){
- if(n <= 1)
- return 1;
- else
- return n*factorial( n-1 );
- }
- //while loop that checks if the factorial is less than the num given
- int i = 2;
- while((1/factorial(i)) < num){
- result = result + (1/factorial(i));
- i++;
- }
- //return the result with 5 decimals
- printf("%.5f\n", result);
- //return result
- return 0;
- }
Add Comment
Please, Sign In to add comment