Skip to content

Instantly share code, notes, and snippets.

@DiegoNaterasPonce
Created March 9, 2016 01:33
Show Gist options
  • Save DiegoNaterasPonce/eb70c9de106cb8fe0aae to your computer and use it in GitHub Desktop.
Save DiegoNaterasPonce/eb70c9de106cb8fe0aae to your computer and use it in GitHub Desktop.
#Quiz4
#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