Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* Prints out a value of e until the order n */
- int main()
- {
- /* Declare and initialize variables if necessary */
- int number, i, j;
- float e = 1.0f, fac_sum = 1.0f;
- /* Prompt the user to enter a number and scan it */
- printf("Please enter a number: ");
- scanf("%d", &number);
- /* Main for loop */
- for (i = 1; i <= number; i++) {
- /* Calculates the factorial of n */
- for (j = number; j > 0; j--) {
- fac_sum *= j;
- }
- e += 1.0f / fac_sum;
- fac_sum = 1.0f;
- }
- /* Print the value of e*/
- printf("Your value of e is: %f", e);
- return 0;
- }
Add Comment
Please, Sign In to add comment