i need help with this pls

Sep 1, 2012 at 9:26am
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
Sep 1, 2012 at 9:34am
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 ???
Sep 1, 2012 at 9:56am
Do you know what recursion is?
Sep 1, 2012 at 10:00am
not really but i think it is to make a function defies itself
Sep 1, 2012 at 10:34am
http://www.cprogramming.com/tutorial/lesson16.html
or if that is not helpful just google "recursion tutorial"
Sep 1, 2012 at 12:52pm
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???
Sep 1, 2012 at 1:01pm
something to this effect:
1
2
3
4
5
6
int fact(int N) //Function that returns N!
cout<<"enter number"<<endl;
cin<<ans;
for(i=0; i<ans; i++) {
	cout<<i<<"! ="<<fact(i);
}

NOTE, this is my version of pseudocode .
Last edited on Sep 1, 2012 at 1:01pm
Sep 1, 2012 at 1:16pm
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
Sep 1, 2012 at 1:18pm
The secret to what? C++, recursion, programming, asking questions?
Sep 1, 2012 at 1:21pm
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??

Sep 1, 2012 at 1:27pm
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/
Sep 1, 2012 at 1:32pm
ok thanks a lot. i highly appreciate ur help
Topic archived. No new replies allowed.