Last active
June 9, 2016 13:17
-
-
Save tyler-boyd/10800371 to your computer and use it in GitHub Desktop.
Quickfactor.cpp
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 <vector> | |
#include <iostream> | |
using namespace std; | |
vector<int> factorize(int num){ | |
int smallest_pairing = num; | |
vector<int> factors; | |
for(int i=1; i<smallest_pairing; i++) | |
{ | |
int pairing = num/i; | |
if(float(num)/float(i) == pairing) | |
{ | |
factors.push_back(i); | |
factors.push_back(pairing); | |
smallest_pairing = pairing; | |
} | |
} | |
return factors; | |
} | |
int main() { | |
int num = -1; | |
cout << "Number? "; | |
cin >> num; | |
cout << endl << endl; | |
if(num < 0) | |
{ | |
cout << "Bad" << endl; | |
return -1; | |
} | |
vector<int> factors = factorize(num); | |
for(int i=0; i<factors.size(); i++) | |
{ | |
cout << "Factor: " << factors.at(i) << endl; | |
} | |
cout << "Done!" << endl << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment