[C++] Finding Factors Of A Number Code
This is the source code with some notes, have questions, post them.
Code:
#include <iostream.h>
int main()
{
int x, r;
cout<<"Enter an integer: ";
cin>>x;
cout<<"The factors of "<<x<<" are: ";
for(int a = 1; a<=x; a++) // for loop to keep each number appearing
{
r=x%a; //modulus (finds remainder when dividing
if(r == 0)// it's basically dividing your number by numbers 1-the integer you've inputted.
{ //if there is no remainder to the number (mean it divides perfectly) the program outputs that number
//thus outputting factors.
// if you want the exe tell me.
cout<<a<<" ";
}
}
cout<<endl;
system ("PAUSE");
return 0;
}