~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <iostream>
using namespace std;
int Factorial(int iNum);
int main()
{
int aNum;
cout<<"Enter a number: ";
cin>>aNum;
cout<<Factorial(aNum)<<endl;
system("PAUSE");
return 0;
}
int Factorial(int iNum)
{
cout<<"We are at number: "<<iNum<<endl;
if (iNum <= 1)
{
cout<<"We are at number: ";
return 0;
}
else
{
return Factorial(iNum - 1);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using this code, I'm able to make it count from the number the user inputs down to zero. I need to find a way to count up from zero back up to the number, using recursion factorial again.
I've tried adding another function that's similar, but got no luck:
int Factorial2(int iNum)
{
cout<<"We are at number: "<<iNum<<endl;
if (1 >= iNum)
{
cout<<"We are at number: ";
return 0;
}
else
{
return Factorial(iNum + 1);
}
}
I've tried a lot of things.(Better than the above code too.)
Anyone have an idea how I can do this?