Factorial program using recursion

Program:

#include<stdio.h>
long int fact(int n);
int main()
{
int m;
long int f;
printf("Enter Number: ");
scanf("%d",&m);
f=fact(m);
printf("Factorial of %d is : %ld",m,f);
    return 0;
}
long int fact(int n)
{
if(n==1)
{
return 1;
}
else
{
return n*fact(n-1);
}
}

Output:





No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...