C program to calculate factorial of a number using recursion.

#include<stdio.h>
#include<conio.h>
void main(){
long int n,ans;
long int factorial(long int x);
printf("Enter an integer number\n");
scanf("%ld",&n);
ans=factorial(n);
printf("factorial of %ld=%ld\n",n,ans);
getch();
}
long int factorial(long int x){
if (x==1) return 1;
else return (x*factorial(x-1));
}

Comments

Popular posts from this blog

C Language Topics in Hindi and English

C language IMP Questions for BSc/BA/BCom/BCA/BE/BTech/MSc/MCA (CS/IT) I year students