c++ programs examples

C++ Program to find the Factorial of a number using Recursive function

c++ programs examples

/* 2. Write a program to find the factorial of a number using Recursive
function */

#include<iostream.h>

 #include<conio.h>

 long int fact(int); //declaration

 void main()

 {

  int no;

  clrscr();

  cout<<“Enter a number to count factorial”<<endl;

  cin>>no;

  cout<<endl<<no<<“! =”<<fact(no);

  getch();

  }

 long int fact(int no)

 {

  if(no==0)

            return 1;

  else

            return (no*fact(no-1));

 }

Leave a Reply

Your email address will not be published. Required fields are marked *