Monday, 30 January 2017

Factorial number with recursion

NIELIT O Level Paper
C Language
 January 2016 Solved

Q8 a) Write a program having a recursive function to calculate the factorial of a number. In the main() function, read the value of the number and then using the recursive function display the result.

Solution :

/*   ################################
     Girfa Student Help
     Factorial recursion  program
     for more visit : http://girfahelp.blogspot.in/p/c-language.html
     ################################

*/
#include<stdio.h>
int fact(int);
void main()
{
     int i;
     printf("enter number for factorial>> ");
     scanf("%d",&i);
     printf("\n\t%d",fact(i));
}

int fact(int n)
{
     if(n==0)
           return 1;
     else
           return(n*fact(n-1));
}

1 comment: