Created
March 29, 2018 23:37
-
-
Save axsddlr/2bdde6d48283acfa6a292d182b43a018 to your computer and use it in GitHub Desktop.
Factorial (Compound Operators) created by Ayysir - https://repl.it/@Ayysir/Factorial-Compound-Operators
This file contains hidden or 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> | |
using namespace std; | |
long int factorial(int n); | |
int main() { | |
int n; | |
cout << "Enter Number "; | |
cin >> n; | |
cout << "Factorial of " << n << " is \n " << factorial(n) << "\n" << endl; | |
return 0; | |
} | |
// function defintion | |
long int factorial(int n) { | |
int i, fact = 1; | |
for (i = n; i >= 1; i--) { | |
fact *= i; // compound opertator | |
cout << "\n" << i << "!" << endl; | |
} | |
cout << "\n" << "Total: "; | |
return fact; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment