### i need help with this pls

Write a recursive function Factorial. The function takes a number and returns the factorial of that number if its more than 0, or else return 1. Main will call this function up to 10 times to Show up to 10 !
The sample output as below.
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
to let u know that i solved the question but i dont know how to call the function 10 times and get the sample output ???
Do you know what recursion is?
not really but i think it is to make a function defies itself
http://www.cprogramming.com/tutorial/lesson16.html
i could calculate the factorial for only one number but i couldnt get for the rest
meaning i couldnt get as the sample output above
should i use a loop or what???
something to this effect:
 ``123456`` ``````int fact(int N) //Function that returns N! cout<<"enter number"<

NOTE, this is my version of pseudocode .
Last edited on
now i got it thank you very much but if u dont mind can u tell me the secret ???
i mean the point so i can learn and apply for another questions???
i am thankful for u
The secret to what? C++, recursion, programming, asking questions?
sorry for makin u confused,
i meant the idea behind using for loop???
why did u put <<fact(i);? while i doesnt exists in the function that return N??

You should really read the tutorial on this site, it will help you a lot. But just a basic explanation or two:
a for loop is generally used to iterate over something, but it has other uses as well. here it is used to call the fact function with different values and print the results.
the line:
`cout<<i<<"! ="<<fact(i);`
cout is the standard output stream and the "<<" are used instead of:
`cout(//stuff to output, more stuff, even more stuff) `
but like i said read the tutorial:
http://www.cplusplus.com/doc/tutorial/
ok thanks a lot. i highly appreciate ur help
Topic archived. No new replies allowed.