Created
March 9, 2016 01:33
-
-
Save DiegoNaterasPonce/eb70c9de106cb8fe0aae to your computer and use it in GitHub Desktop.
#Quiz4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
int factorial(int x) | |
{ | |
if (x == 1 || x == 0) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return x * factorial(x - 1); | |
} | |
} | |
float euler_calc(float y) | |
{ | |
float x = 0.0, answer = 0.0; | |
do | |
{ | |
answer += 1.0/(factorial(x)); | |
x = x + 1; | |
} | |
while(x <= y); | |
return answer; | |
} | |
int main() | |
{ | |
float y, answer, x = 0.0; | |
cout << "Tell me a number: \n "; | |
cin >> y; | |
cout << "The answer is " << euler_calc(y) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment