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

Computer Network & Computer Features | Bal Varg | Computer Questions List!

  Computer Network & Computer Features 1) _______ is a thin strip like bar present at the bottom of the screen.   Taskbar 2) _______ ser...