Need help on displaying factors of an input number in a decreasing order.

Aug 1, 2012 at 2:00pm
I still can't figure out how to display the factors backwards. Tried playing with the algorithms but ending up with errors. lol. Please someone help me.

#include <iostream>
using namespace std;



int main ()
{


int counter;
int fnum;

cout<<" Please input a number and press [ENTER].";
cin>>fnum;

for (counter=1;counter<=fnum;counter++)
{if (fnum%counter==0)
cout<<counter<<endl;
}
return 0;
}


For example , If I input 36 , and the output would be 1 , 2 , 3 , 4 , 6 , 9 , 12 , 18 , 36. But how can i make it to display the other way around?
Last edited on Aug 1, 2012 at 2:05pm
Aug 1, 2012 at 2:10pm
for ( counter=fnum; counter>0; counter-- )
Last edited on Aug 1, 2012 at 2:10pm
Aug 1, 2012 at 2:13pm
Reverse the order of your loop?
Aug 1, 2012 at 2:17pm
oh thanks alot lowestOne! got it workin now.

@PanGalactic yeah. Anyways , its working now. Thanks guys.
Topic archived. No new replies allowed.