Structure of the Problem Requirements
In this Important Problem we deal with the Finding Factorial of a number using Recursion or Recursive Function : Recursive function is a type of function which calls itself in Function Definition Code Segment until a terminating condition reached. In the following program "fact( )" is a recursive function.
Source Code
#include<stdio.h>
int fact(int n);
int main()
{
int number,ans;
printf("\n \n *************** FINF FACTORIAL ************** \n\n\n");
printf("Enter Number : ");
scanf("%d",&number);
ans=fact(number);
printf("\n Factorial : %d \n \n",ans);
return 0;
}
int fact(int n)
{
int f;
if(n==1)
return (1);
else
f=n*fact(n-1);
return (f);
}
//Use long int in place of int to find factorial of large number like 100 or so on..
Output of the Program
Factorial |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment