TheAlgorithms-C/misc/Factorial.c
viditkulshreshtha 64c28f76a2
added a condition
If the user enters the input as 0 (zero) then also the output should be one
2017-11-02 14:51:48 +05:30

21 lines
284 B
C

#include <stdio.h>
int fat(int number){
if (number == 1 || number == 0)
return 1;
else
return number*fat(number-1);
}
int main(){
int number;
//Asks the factorial of the number n
printf("Number: ");
scanf("%d", &number);
printf("%d\n", fat(number));
return 0;
}