#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int n;
cout << "Input n: "; cin >> n;
cout << "Factorial is " << tgamma( n + 1.0 ) << endl;
}
Input n: 150
Factorial is 5.71338e+262
If you want the exact answer as a long string of digits then you will either have to use a big-number class or simply write a short routine to do long multiplication (the same way as by hand) with a vector<int>
First, you need a concrete problem statement, because I can solve 150 in ways you haven’t even thought of yet.
Next, you need to review your lecture notes and book. Your homework assignments are typically designed to make you use stuff you should have just learned. So, for example, if your last class was all about “loops”, chances are your homework will require you to use a loop.
Third, figure out how you would solve it on a piece of paper. Try to design your code to do the same thing / think the same way.
Finally, write some code and give it a compile or two. Figure out what works and what doesn’t. When you get stuck, post back here with the following information:
• [code] your code [/code]
• what it is supposed to do
• what it does instead (if it compiles)
• the first few lines of complaint your compiler spits out (if it does not compile)
Otherwise, you are just asking us to do your homework, and many of us personally find it much more entertaining to watch wimps squirm and fail than become someone we have to work with later.