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
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?: