+ 1

I have number(N) and i have to print all the number between 1 to square of that number(N*N)

function patternOfN(N) { for(i=1;i<=N;i++){ let s = ""; for(j=i;j<=i*N;j++){ s = s+j+" "; } console.log(s); } } input is 4 desire output 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 but what i get 1 2 3 4 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 11 12 4 5 6 7 8 9 10 11 12 13 14 15 16 so where i am wrong ?

29th May 2022, 3:15 PM
TINKLE DASH
TINKLE DASH - avatar
17 odpowiedzi
+ 1
count=0;     for(i=1;i<=N*N;i+=N){         count+=1;         let s = "";    for(j=i;j<=count*N;j++){        s = s+j+" ";    }    console.log(s);     } here I solve this
29th May 2022, 6:05 PM
TINKLE DASH
TINKLE DASH - avatar
+ 2
TINKLE DASH Check step by step and read carefully It will print
29th May 2022, 6:05 PM
A͢J
A͢J - avatar
+ 1
Manav Roy but I have to put that as row and column
29th May 2022, 3:27 PM
TINKLE DASH
TINKLE DASH - avatar
+ 1
TINKLE DASH Use a 3rd variable function patternOfN(N) { var k = 0; for(i = 1; i <= N; i++) { let s = ""; for(j = 1; j <= N; j++) { k++; s = s + k + " "; } console.log(s); } } patternOfN(4)
29th May 2022, 5:32 PM
A͢J
A͢J - avatar
+ 1
TINKLE DASH You can just break lines on every output which is multiple of the input. Or, if you prefer nesting, do both loops from 1 to N. Then output the sum of i * N and j. This way, every line gets incremented by N, which is what I guess you need (the description isn't clear).
29th May 2022, 8:09 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Ah, it's solved already. Didn't get it from last message.
3rd Jun 2022, 9:33 PM
Emerson Prado
Emerson Prado - avatar
0
A͢J it print nothing
29th May 2022, 5:41 PM
TINKLE DASH
TINKLE DASH - avatar
0
So loop from 1 to N*N. No need for nested loops.
29th May 2022, 6:39 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado but I need to be print it in a tabular form
29th May 2022, 7:59 PM
TINKLE DASH
TINKLE DASH - avatar
0
Emerson Prado how can I break line of input can you give me the solution
3rd Jun 2022, 5:49 PM
TINKLE DASH
TINKLE DASH - avatar
0
You can add a line break - '\n' - where needed
3rd Jun 2022, 6:21 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado but it's just for input 4 It's not a generic code for every input
3rd Jun 2022, 6:22 PM
TINKLE DASH
TINKLE DASH - avatar
0
TINKLE DASH The function you wrote is generic - it has parameter N exactly for that. But what difference does it make?
3rd Jun 2022, 6:26 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado the pattern what I want is **** **** **** **** But I get here * ** *** **** For that I try to rectify inside the function count=0;     for(i=1;i<=N*N;i+=N){         count+=1;         let s = "";    for(j=i;j<=count*N;j++){        s = s+j+" ";    }    console.log(s);     } here I solve this
3rd Jun 2022, 6:30 PM
TINKLE DASH
TINKLE DASH - avatar
0
You're quite close to the solution, but the communication is being incomplete. So let's do it the right way: 1. Save this code in Code Playground 2. Include a link to it in the question description 3. Include the whole output in the question description 4. Explain your current difficulty in the question description 5. Remove all code from the question description Then, I can see exactly where you are and suggest the next step.
3rd Jun 2022, 6:39 PM
Emerson Prado
Emerson Prado - avatar
0
Yup 😊
3rd Jun 2022, 9:41 PM
TINKLE DASH
TINKLE DASH - avatar