Download to read offline
![Write a program that prompts the user to enter a positive integer and displays all its smallest factors in decreasing order. For example, if the integer is 120, the smallest factors are displayed as 5, 3, 2, 2, 2. Use the StackOflntegers class to store the factors (e.g., 2, 2, 2, 3, 5) and retrieve and display them in reverse order. Solution #include #include using namespace std; class StackOfIntegers { int s[100],top; public: StackOfIntegers() { top=-1; } void put(int n) { top++; s[top]=n; } int get() { if(top==-1) { return -1; } return s[top--]; } }stack; void primeFactors(int n) { while (n%2 == 0) { stack.put(2); n = n/2; } for (int i=3; i<=sqrt(n); i=i+2) { while (n%i==0) { stack.put(i);](https://image.slidesharecdn.com/writeaprogramthatpromptstheusertoenterapositiveintegerand-230803004605-9755e8dd/75/Write-a-program-that-prompts-the-user-to-enter-a-positive-integer-and-pdf-1-2048.jpg)

The document describes a program that prompts the user for a positive integer and displays its smallest factors in decreasing order using a stack data structure. It includes C++ code that implements this functionality by computing prime factors and storing them in a stack, which are then retrieved and displayed in reverse order. An example is provided where the integer 120 results in the factors 5, 3, 2, 2, 2.
![Write a program that prompts the user to enter a positive integer and displays all its smallest factors in decreasing order. For example, if the integer is 120, the smallest factors are displayed as 5, 3, 2, 2, 2. Use the StackOflntegers class to store the factors (e.g., 2, 2, 2, 3, 5) and retrieve and display them in reverse order. Solution #include #include using namespace std; class StackOfIntegers { int s[100],top; public: StackOfIntegers() { top=-1; } void put(int n) { top++; s[top]=n; } int get() { if(top==-1) { return -1; } return s[top--]; } }stack; void primeFactors(int n) { while (n%2 == 0) { stack.put(2); n = n/2; } for (int i=3; i<=sqrt(n); i=i+2) { while (n%i==0) { stack.put(i);](https://image.slidesharecdn.com/writeaprogramthatpromptstheusertoenterapositiveintegerand-230803004605-9755e8dd/75/Write-a-program-that-prompts-the-user-to-enter-a-positive-integer-and-pdf-1-2048.jpg)
