programmania
Thursday, 4 April 2013
Factorial of a number using resursion
#include<stdio.h>
#include<conio.h>
int fact(int);
main()
{int y,n;
printf("Enter a number to find its factorial\n");
scanf("%d",&n);
y=fact(n);
printf("factorial = %d",y);
getch();
}
int fact(int x)
{
if(x>1)
return x*fact(x-1);
else
return 1;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment