I wrote this factorial program, which i expected should have returned an answer, but i didn't. I know it has to be a small conceptual mistake, but i just couldn't get it. Please help!
Code:
#include <stdio.h>
#include <stdlib.h>
int fact(int num);
void main() {
int number, factorial;
printf("Enter Number : ");
scanf("%d", &number);
factorial = fact(number);
printf("Factorial : %d", factorial);
}
int fact(int num){
int res ;
if(num==0){
return 1;
}
while(num!=0){
res = num*fact(num-1);
}
return res;
}
The code compiles fine and even runs...but it just gets stuck at
"factorial = fact(number);" in the main..