Q. Write a C program to accept any number from user and calculate its factorial value using recursion method.
Ans.
/*c program to find out factorial value using recursion method*/
#include<stdio.h>
#include<conio.h>
int fact(int );
int main()
{
int num,res;
printf("Enter any number: ");
scanf("%d", &num);
res = fact(num);
printf("Factorial value is: %d",res);
getch();
return 0;
}
int fact(int n)
{
int f;
if(n==1)
return(1);
else
f = n*fact(n-1);
return(f);
}
/************Output************/
Ans.
/*c program to find out factorial value using recursion method*/
#include<stdio.h>
#include<conio.h>
int fact(int );
int main()
{
int num,res;
printf("Enter any number: ");
scanf("%d", &num);
res = fact(num);
printf("Factorial value is: %d",res);
getch();
return 0;
}
int fact(int n)
{
int f;
if(n==1)
return(1);
else
f = n*fact(n-1);
return(f);
}
/************Output************/
Screen shot for calculate factorial value using recursion method |
Comments
Post a Comment