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; }
Results 1 to 1 of 1
- 07 Apr. 2010 10:29pm #1
[C++] Finding Factors Of A Number Code
LG's Dyke. Enough. Said.