So right now, when I run this with an integer of 25, it spits out 1, 5, 25. I need it to be reversed like 25, 5, 1. Please help!!
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int i = 0;
int integer = 0;
cin >> integer;
for ( i = 1; i <= integer; i++ )
{
if (integer % i == 0)
cout << i << endl;
}
system("pause");
return 0;
}
you can do almost anything in a for loop.
such as
for( i = 25; i >0; i /=5;)
cout << i << endl;
you are not confined to ++ and --, you can put any legal expression in there.
Here you can just reverse the loop,
i = integer, i >= 0, i-- if I did that right.
Last edited on
Hmm...I tried that last one and it gave me a runtime error
sorry! I triggered divide by zero with my lack of attention to details!
Thanks integralfx!! it worked!