C++ | Factorial of number using function

Note:- If you are looking for simple program of factorial(not using function), please see this.

C++ | Factorial of number.

else continue here……


The program is to find the factorial of number using function. The simple program(not using function) link is above. The program using function is given below. The program is not extendable. Go enjoy the program. Lets begin…..

Program to find the factorial of number using function

//function prototype
int fact(int);
//main function
void main()
//clear the screen.
//declare variables as int.
int no,fac;
//Input the number and save it in 'no'
cout<<"Enter the no."<<endl;
//calculate factorial using function.
//print factorial
cout<<"Factorial of "<<no<<" is "<<fac;
//get character

int fact(int no)
int i,f=1;


Enter the no.
Factorial of 5 is 120

How does it work

  1. You enter the number.
  2. The function calculates the factorial.
  3. The factorial is printed.

Extending it

The program cannot be extended.


  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Declare the function prototype.
  3. Add void main.
  4. Start program by first clearing the screen.
  5. Declare the variables as int (name them as you want.)
  6. Add the cout and cin of number.
  7. Call the function and save the factorial in variable.
  8. Add the cout of factorial.
  9. Add the function definition outside the void main().

At the end

You learnt creating the C++ program of Factorial using function. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Join India's Largest Code Learning Community on Uphub.io Get it on Google Play
Sharing options: