Feb 14, 2017 at 9:10pm
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;
}
Feb 14, 2017 at 9:18pm
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 Feb 14, 2017 at 9:20pm
Feb 14, 2017 at 9:38pm
Hmm...I tried that last one and it gave me a runtime error
Feb 14, 2017 at 10:15pm
sorry! I triggered divide by zero with my lack of attention to details!
Feb 14, 2017 at 10:47pm
Thanks integralfx!! it worked!