code.cpp 326 B

12345678910111213
  1. // Create a function that takes a number as its argument and
  2. // returns an array of all its factors.
  3. std::vector<int> factorize(int n) {
  4. std::vector<int> results={};
  5. for (int a=1;a<=n;a++){
  6. // check to see if it is a factor. and then store the factor
  7. if (n%a==0) {
  8. results.push_back(a);
  9. }
  10. }
  11. return results;
  12. }