Monday 5 November 2018

LESSON 3 Factorial of a number using recursion C Programming

Factorial of a number using recursion

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf("Enter the limit");
scanf("%d",&n);
f=fact(n);
printf("factorial is %d",f);
getch();
}
int fact(int x)
{
int p;
if(x==0)
return(1);
else
{
p=x*fact(x-1);
}
return(p);
}

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes