Skip to content

Commit c00d0d0

Browse files
Merge pull request matthewsamuel95#264 from BlueFRJ/All-factors-of-a-given-Number
Create All factors of a given Number.cpp
2 parents c2e7f68 + c348530 commit c00d0d0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//We include de I/O library
2+
#include <iostream>
3+
/* We include the stdenteredNumeramespace so we don't have to write std::
4+
Everytime we want to use "cout" or "cin" */
5+
using namespace std;
6+
7+
int main()
8+
{
9+
// We declare our variables
10+
int enteredNumer, i, factorization;
11+
12+
// Ask for a number
13+
cout << "Enter a number of your choice (positive and integeer): ";
14+
// Assing the entered value to the "enteredNumer" variable
15+
cin >> enteredNumer;
16+
17+
cout << "These are the factors for " << enteredNumer << ": " << endl;
18+
19+
factorization = enteredNumer;
20+
21+
// Every number has 1 as it's factor, so we'll say this right away
22+
cout << 1 << endl;
23+
24+
// Check the factors (starting with 2, until the number is reached)
25+
for(i = 2; i <= enteredNumer; ++i)
26+
{
27+
// If the divided number has 0 as the division reminder, it'll be a factor
28+
29+
while (factorization % i == 0){
30+
// Print this number everytime
31+
cout << i << endl;
32+
33+
// As it is a factor, let's divide by it to find the next one!
34+
factorization = factorization / i;
35+
};
36+
}
37+
38+
return 0;
39+
}
40+

0 commit comments

Comments
 (0)