Monday, January 10, 2011

factorial using recursion

/*****************************
* Umang B Bhatt *
* bhatt.umang7@gmail.com *
*****************************/

/**
* program for finding factorial using recursion
*/


#include<stdio.h>

int
fun(int n)
{


if
(n>1)
{

return
n*fun(n-1);
}


else

{

return
1;
}
}


void
main()
{


int
n =3 ;
printf("\nEnter a number to find factorial: ");
scanf("%d",&n);

printf("Factorial is: %d\n",fun(n));
}

No comments:

Post a Comment