F Factorial of a number using function in CPP | CodeTheta

Factorial of a number using function in CPP

August 05, 2019

Code :
#include<iostream>
#include<conio.h>
using namespace std;
int factorial(int);

int main(){
    int number;
    cout<<"Enter a number: ";
    cin>>number;
    factorial(number);
}

int factorial(int x) {
    int fact = 1, i;
    for(i=1;i<=x;i++) {
    fact = fact *i;
    }
 cout<<"Factorial is: "<<fact;
 return 0;
   
}


Output : 
Enter a number: 3
Factorial is: 6

IDE Used To Test This Code : DEV C++

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment