Tuesday, 13 March 2018

Recursion in C

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

float factorial(float);
void main()
{
    float a,fact;
    clrscr();   
    printf("Enter any number :  ");
    scanf("%f",&a);
    fact=factorial(a);
    printf("Factorial of a :  %f",fact);
    getch();
}
float factorial(float x)
{

   float f;
   if(x==1)
    return(1);
   else
    f=x*factorial(x-1);
    return (f);
}


No comments:

Post a Comment