04-19-2015, 10:28 PM
prime factorization
PHP Code:
//Asks the user for a number, then computes the prime factorization of it.
//Jarvis, Alex J.
//3/25/15
//Language c++ / g++ target
#include <iostream>
using namespace std;
#include "Stack.h" //Header file for stack functions
int main(void)
{
Stack prime; //Create an instance of stack "prime"
int input, i;
cout<<"Enter an integer to be prime factored: ";
cin>>input;
cout<<endl;
for (int i=2; i <= input; i++)
{
while(input % i == 0)
{
input /= i;
prime.push(i);
}
}
prime.display(cout); //Prints the factors out
return 0;
}