C program to calculate factorial of number N using function.

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


}

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