Thursday, June 19, 2014

RECURSIVE FUNCTION TO FIND FACTORIAL OF GIVEN NUMBER

#include<stdio.h>
int fact(int n);
void main(){
  int num,f;
  printf("\nEnter a number: ");
  scanf("%d",&num);
  f=fact(num);
  printf("\nFactorial of %d is: %d",num,f);
  getch();
}

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

No comments:

Post a Comment

Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions!

Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions! :  1) What is digital citizenship? 2) What is a digital citi...