Skip to content

Instantly share code, notes, and snippets.

@Konard
Forked from epoll-reactor/file.cpp
Last active January 26, 2020 10:53
Show Gist options
  • Save Konard/f135af9d0b77bf85f7ee7deeb4ee87e3 to your computer and use it in GitHub Desktop.
Save Konard/f135af9d0b77bf85f7ee7deeb4ee87e3 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
int foo1(int n)
{
if (n == 0)
{
return 3;
}
if (n == 1)
{
return 2;
}
else
{
return foo1(n-1) * foo1(n-2) - n;
}
}
int foo2(int n)
{
int nMinus2 = 3, nMinus1 = 2, result = 0;
if (n == 0)
{
result = nMinus2;
}
else if (n == 1)
{
result = nMinus1;
}
else
{
for (int i = 2; i <= n; i++)
{
result = nMinus2 * nMinus1 - i;
nMinus2 = nMinus1;
nMinus1 = result;
}
}
return result;
}
int main()
{
int n = 0;
cout << "cin n: ";
cin >> n;
cout << "foo1(n): " << foo1(n) << endl;
cout << "foo2(n): " << foo2(n) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment