0
To find factorial of a number by using pointers in c program
test case1: input 5 output 120
5 Respuestas
+ 3
There's 2 common ways of doing factorials.
One is with a simple loop.
You only need to keep multiplying the number until it reaches 1.
for(int i = myNum-1; i >= 1; i--)
myNum *= i;
// 5 * 4 * 3 * 2 * 1 = 120
(Not sure if this is the same syntax for C, I've never done C).
The other way is recursion.
Keep re-calling the function with a smaller number until it reaches 1. In which case, return 1.
I won't be posting codes, but hopefully the explanation helps.
+ 1
You've posted at least five basic questions in a short time. All of them with a single test case, and zero lines of code. Are you asking us to help you learn, or just to do your homework?
+ 1
You have zero codes in your playground. If you solved them but your solution doesn't work, post your code and your questions and we will do our best to help.
Don't just ask for "a solution" - you'll lose a valuable chance to learn...
0
Its not homework .I solved all the questions I posted but not yet getting proper output though the both test cases passed .so just solve if u can .I wanna solution .....
0
thanks a lot .....