Pair of numbers

Hello
I have homework to do. i have to write a cpp code I have to cin N and it has to cout every possible pair of numbers from 1 to N. for ex : we input 3 . Program outputs
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Hint: Use a for-loop nesting another for-loop
I am very beginner at it could u write that for-loop for me please ? thanks
I won't write the for-loop for you, it's your homework after all..

But I'll try to make you understand.
Consider a for-loop to print 3 numbers. It would print 1, 2, 3.
Now what if we wrote a for-loop inside this for-loop which we had written earlier, to print 3 numbers again, and remove the previous cout statement?

We would get something like this: 1, 2, 3, 1, 2, 3, 1, 2, 3.

For the 1st iteration of the big for loop we get 3 iterations in the inner for-loop which print 1, 2, 3.
Likewise 2nd and 3rd iterations of the big for loop also have 3 inner iterations each.

Now what if instead of just printing the inner iteration's value, we also print the outer loop's iteration's value?
Then we would get something like this?:

1 (of outer) : 1 (of inner)
1: 2
1: 3
2: 1
2: 2
2: 3
3: 1
3: 2
3: 3

Now you just need to think about how to frame those two for-loops that's all. And if you have done this before then it shouldn't be hard.

Thanks a lot buddy . U helped me a lot :)
Topic archived. No new replies allowed.