Friday, April 10, 2015

21. Write advantage of function.Write a recursive function to calculate the factriol of any integer number.

#include<stdio.h>
#include<conio.h>
long int factorial(int);
void main()
{
int n;
long int fact;
clrscr();
printf("\n Input a number:-");
scanf("%d",&n);
fact=factorial(n);
printf("\n factorial of %d is %1d",n,fact);
getch();
}
long int factorial(int n)
{
if(n==1)
  return(1);
else
  return(n*factorial(n-1));
}

No comments:

Post a Comment