Factoring Numbers

Hey guys, I am a new c++ programmer, and I created this program to factor numbers and tell u if they are prime. However, I would like to make it so that it does not repeat factors. For example, for 10, I don't want it to say:
Factors:
5,2
2,5

Thank you, heres the code.



#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

while(1==1){

float x;
cout<<"Enter a number to see if it is prime"<<endl;
cin>>x;
int test=0;
int half=x/2;
for(float y=2; y<x; y++){

float z=x/y;
int a=x/y;
if(a!=z){

int b=y+1;
if(b==x && test==0){

cout<<"Prime"<<endl;

}

}
if(a==z){
test++;
if(test==1){
cout<<"Factors of "<<x<<":"<<endl;
}
cout<<y<<", "<<z<<endl;
}
}


}

return 0;
}
Last edited on
Topic archived. No new replies allowed.