Guest User

Untitled

a guest
Oct 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. void show( int *arr ,int num );
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. int num=0;
  10. int numfactor=0;
  11. int numarry=0;
  12. char error[20];
  13. cout << "what number do you want to factor: ";
  14. while (!(cin >> num)) {
  15. cout <<"try again";
  16. cin >> error;
  17. }
  18. for (int i=1;i<=num;i++)
  19. if (!(num % i))
  20. numfactor++;
  21. int * factor =new int [numfactor];
  22. for (int i=1;i<=num;i++)
  23. if (!(num % i)) {
  24. cout <<i<<"\n";
  25. factor[numarry];
  26. numarry++;
  27. }
  28. cout <<num << " has these factors ";
  29. show(factor,numfactor);
  30. cout <<"\n";
  31. system("PAUSE");
  32. return EXIT_SUCCESS;
  33. }
  34. void show (int arr[] ,int x)
  35. {
  36. cout <<arr[0];
  37. for (int i=1;i < x;i++)
  38. cout <<","<<arr[i];
  39. }
Add Comment
Please, Sign In to add comment