Advertisement
jaskamiin

WORKING factoring program

Jun 8th, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. double factors(int a, int b);
  7.  
  8. int main()
  9. {
  10. int x;
  11. int y = 1;
  12.  
  13. cout << "Enter an integer" << endl;
  14. cin >> x;
  15.  
  16. factors(x,y);
  17. cout << endl;
  18.  
  19. system("pause");
  20. return 0;
  21. }
  22.  
  23. double factors(int a, int b) {
  24.  
  25. while(b <= a) { //while a is lesser than or equal to b
  26. b/a; // divide b by a
  27. if (a % b == 0){ //if the remainder is 0
  28. cout << b << " "; // print b
  29. } //add 1 to a
  30. b++;
  31. } // run again
  32. return b;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement