Skip to content

Commit

Permalink
Adding factorial code in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
riyapannu7 committed Oct 15, 2017
1 parent 5d8dd6e commit 98eaf53
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions C++/factorial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Created by Riya Pannu on 15/10/17.

#include<iostream>
using namespace std;

long long int factorial(long long int n) {
if (n == 0)
return 1;
else
return n * factorial(n-1);

}

int main() {
long long int n;
cout<<"Enter a number \n";
cin >> n;

long long int result = factorial(n);
cout << "The factorial of "<<n<<" is "<<result << endl;
return 0;
}

0 comments on commit 98eaf53

Please sign in to comment.