Code:
#include<iostream>
#include<stack>
using namespace std;
void PrimeFactors(int n)
{
// Stores prime factors of n
// in decreasing order
stack < int >x;
int i = 2;
while (n != 1) {
if (n % i == 0) {
// Insert i into stack
x.push(i);
while (n % i == 0) {
// Update n
n = n / i;
}
}
// Update i
i++;
}
// Print value of stack x
while (!x.empty()) {
printf("%d ", x.top());
x.pop();
}
}
// Driver Code
int main()
{
int n;
cout << "Enter value:";
cin >> n;
// function Call
PrimeFactors(n);
return 0;
}
insert
Code:
Output:
Enter value:76 19 2
im supposed to see
19 2 2