csansoon

P4.10 P57474 Iterative factorial

Oct 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int factorial(int n) {
  5.     int x=1;
  6.     for (int i=1;i<=n;i++) x=x*i;
  7.     return x;
  8. }
  9.    
  10.    
  11.    
  12. int main(){
  13.     int n;
  14.     cin >> n;
  15.     cout<<factorial(n)<<endl;
  16. }
Add Comment
Please, Sign In to add comment