# I have a question

Row = 5, Col = 8;
for(int i=0;i<Row;i++)
{
for(int j=0;j<Col;j++)
{
//Print 0 to 40, just by using i and j, don’t use any variables.
}
}

1 Like

# you can use the formula (i*Col+j) for each iteration and get your desired output.

This one is definitely working but I need to do it just by using i and j. No variables inside.

`i` and `j` are variables too!

``````public class Main
{
public static void main(String[] args) {
int Row = 5;
int Col = 8;
for(int i = 0 ; i<Row ;i++){
if(i == 4) {
System.out.print("40");
break;}
for(int j = 0 ;j<=Col;j++){
System.out.print(i+""+j+" ");

}
System.out.print(i+""+9);
System.out.println();
}
}
}
``````

# By using this technique you can get 0-40 notice we have not used any internal variable just used if else syntax.

``````#include <iostream>

int main() {
int Row = 5, Col = 8;

for (int i = 0; i < Row; i++) {
for (int j = 0; j < Col; j++) {
std::cout << 8 * i + j << " ";
}
}
std::cout << 40;

return 0;
}

``````
1 Like

python
row =5
col=8
for i in range(row):
for j in range(1,col+1):
print(col*i + j)

int main() {
int Row = 5;
int Col = 8;

``````for (int i = 0; i < Row; i++) {
for (int j = 0; j < Col; j++) {
int value = i * Col + j;
std::cout << value << " ";
}
std::cout << std::endl;  // Move to the next line after each row
}

return 0;
``````

}