#include<stdio.h>
#include<conio.h>
long int facto(int n)
{
if(n==1)
{
return 1;
}
else return n*facto(n-1);
}
void main()
{
long int f;
int num;
printf("Enter any number :");
scanf("%d",&num);
if(num>0)
{
f=facto(num);
printf("factorial is %d",f);
}
else
{
printf("\n error:given number is %d negative",num);
}
}
Flowchart:
Algorithm:-
· start
· read n
· if(n>0) then f=1
· if(n==1) then f=f*n and n=n+1
· write fact -stop
· else error
· stop
Program:-
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer