C++ Nested for loops

I need to make a program where it prompts for an integer greater than one that represents the low end of a range and a second integer greater than or equal to the first integer that represents the high end of a range and the program will print the factors starting from 1 of the inters in this range. Everything in my code works, except that the output of the program looks different from the sample output that have been given, I figure its the nested for loops that I have issues with.

Sample output:
low range: 2
high range: 4

2: 1,2
3: 1,3
4: 1,2,4

for (i=low; i<=high; i++)
  {
    for (j=1; j<=i; j++)
    {
      if (i%j == 0)
      {
        cout << i << ":" << j << ", ";
      }
    }
    cout << endl;
   }


Output of this program:
2:1, 2:2,
3:1, 3:3,
4:1, 4:2, 4:4,
Last edited on
What is the question?

PS. Please use code tags, when posting code. See http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Topic archived. No new replies allowed.