+ 2
Could anyone tell me for the code below, what is the role of each i and j ??
#include <iostream> using namespace std; int main(){ int i,j; for(int i=1;i<=20;i++){ for(int j=1;j<=i;j++){ cout<<j; } cout<<"\n"; return 0; }
5 Respostas
+ 3
@RiGeL your for loop on "i" is missing its closing curly bracket, just notify you.
+ 3
i and J here are Iterators, they are here to make a loop. they are assigned a value, then you specify the expression that they have to fallow and typically you increment or decrement then in every loop step
+ 2
@paul thank you alot
+ 2
@Ipang thank you
0
The inner loop will print all the values of j each time the outer loop runs, from 1 to the current value of i.
So for i=4, it will print 1,1,2,1,2,3,1,2,3,4.