Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

factorial function C++

#include<iostream>

using namespace std;

int factorial(int x){
	if(x==0){               // Base-case   ( VERY IMPORTANT)
		return(1);
	}
	else{
	   return(x*(factorial(x-1))) ;
	}
}
	
int main(){
    int no = 5;
    
    cout << factorial(no) ;    // 120
}
Source by www.cplusplus.com #
 
PREVIOUS NEXT
Tagged: #factorial #function
ADD COMMENT
Topic
Name
5+6 =