#include<stdio.h>
#include<conio.h>
long factorial(int);
void main()
{
int num;
long f;
printf("ENTER A NUMBER TO FIND FACTORIAL :");
scanf("%d",&num);
if(num<0)
printf("NEGATIVE NUMBERS ARE NOT ALLOWED");
else
{
f = factorial(num);
printf("%d!=%ld",num,f);
}
getch();
}
long factorial(int n)
{
if(n==0)
return(1);
else
return(n*factorial(n-1));
}
Output of code:
#include<conio.h>
long factorial(int);
void main()
{
int num;
long f;
printf("ENTER A NUMBER TO FIND FACTORIAL :");
scanf("%d",&num);
if(num<0)
printf("NEGATIVE NUMBERS ARE NOT ALLOWED");
else
{
f = factorial(num);
printf("%d!=%ld",num,f);
}
getch();
}
long factorial(int n)
{
if(n==0)
return(1);
else
return(n*factorial(n-1));
}
Output of code:
No comments:
Post a Comment