Skip to content

Commit 9e2f0ff

Browse files
committed
[New] Factorial
1 parent 1fbc023 commit 9e2f0ff

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

factorial/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// main.cpp
3+
// factorial
4+
//
5+
// Created by samuel muloki on 12/05/2019.
6+
// Copyright © 2019 line23. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
11+
using namespace std;
12+
13+
int main(int argc, const char * argv[]) {
14+
unsigned int num;
15+
unsigned long long factorial = 1;
16+
cout <<"Enter a postive integer: ";
17+
cin >> num;
18+
for (int i = 1; i <= num; i++) {
19+
factorial *= i;
20+
}
21+
cout <<"factorial of "<<num<<" = "<<factorial;
22+
cout <<endl<<endl;
23+
return 0;
24+
}

0 commit comments

Comments
 (0)