Created
April 10, 2017 16:53
-
-
Save tornikegomareli/2adc5b342653bfc08cb8193f4e83b27b to your computer and use it in GitHub Desktop.
Search Factorial with recursive function #165
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
using namespace std; | |
int factorial(int number) | |
{ | |
int temp; | |
if (number <= 1) | |
return 1; | |
temp = number * factorial(number - 1); | |
return temp; | |
} | |
int main() | |
{ | |
int number; | |
cout << "Please enter a positive integer: "; | |
cin >> number; | |
if (number < 0) | |
cout << "That is not a positive integer.\n"; | |
else | |
cout << number << " factorial is: " << factorial(number) << endl; | |
cin.get(); | |
cin.get(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment