Skip to content

Instantly share code, notes, and snippets.

@axsddlr
Created March 29, 2018 23:37
Show Gist options
  • Save axsddlr/2bdde6d48283acfa6a292d182b43a018 to your computer and use it in GitHub Desktop.
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
#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