0

To find factorial of a number by using pointers in c program

test case1: input 5 output 120

25th Jul 2017, 4:53 PM
MADHU MITHA K
MADHU MITHA K - avatar
5 ответов
+ 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.
25th Jul 2017, 6:41 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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?
25th Jul 2017, 5:20 PM
Bogdan Sass
Bogdan Sass - avatar
+ 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...
25th Jul 2017, 6:11 PM
Bogdan Sass
Bogdan Sass - avatar
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 .....
25th Jul 2017, 5:24 PM
MADHU MITHA K
MADHU MITHA K - avatar
0
thanks a lot .....
26th Jul 2017, 12:55 AM
MADHU MITHA K
MADHU MITHA K - avatar