I need help creating a C++ program that computes the factorial of an integer between 1-20 using a nested loop. Integer and respective factorial must be printed in 2 columns on the screen.
Here's what I have so far. I don't know how to get the integers and factorials to print though :/ #include<iostream> using namespace std; int main() { int num,factorial=1; cout<<" Enter Number To Find Its Factorial: "; cin>>num; for(int k=1; k<=num; k++) { factorial=factorial*k; } cout << "Interger" << " " << "Factorial" << endl; cout << num << " " << factorial << endl; system ("PAUSE"); return 0;
Can you please show me the output you are getting on console?
Integer Factorial 4 24 But according to the assignment it should also be showing the factorials for 1-3 as well. 17! and a few others are also coming up wrong and I have no idea how to fix those.
Can i do this in java?
Not really sure what that is other than another language. If it'll help solve the problem in C++ then I guess. It's a C++ class though.
Well Java is a object oriented language too,the only difference would be the syntax.
Oh okay. Well by all means. I'm just so frustrated with this.
Don't worry it's easy :)
here you go.
amorable, output the column headers before your for loop and output num and factorial inside the loop.
Do a loop from 1 to integer. do the math output "Integer" loopNumber "Factorial" factorial close the loop
oh yeah, @rsmith6559 got it Output "Integer" "Factorial" Do a loop from 1 to integer. do the math output loopNumber factorial close the loop
Join our real-time social learning platform and learn together with your friends!