Help me in solving PPATTERN problem

My issue

include
using namespace std;

int main() {
int t;
cin>>t;
while (t–){
int n;
cin>>n;
int v=0;
for(int i=1;i<=nn; i++){
for(int j=1; j<=n
n; j++){
v=v+j;
cout<<v;
}

``````    }
}
return 0;
``````

}
what changes should be done

My code

``````#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while (t--){
int n;
cin>>n;
int v=0;
for(int i=1;i<=n*n; i++){
for(int j=1; j<=n*n; j++){
v=v+j;
cout<<v;
}

}
}
return 0;
}

``````

Problem Link: PPATTERN Problem - CodeChef

@nandinish09120
Your code is not right .
Its just implementation problem which u can do in many ways .
This is one of the ways .
Just dry run it on rough copy for better understanding .

``````#include <iostream>
using namespace std;

int main() {
int t;
cin >> t;
while(t--) {
int N;
cin >> N;
int num = 1;
int arr[100][100];
int c = 0;
while(num != N * N + 1) {

for(int  i = 0;i < N;i++) {
for(int j = 0;j < N;j++) {
if(i + j == c) {
arr[i][j] = num;
num++;
}
}
}
c++;
}
for(int i = 0;i < N;i++) {
for(int j = 0;j < N;j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
}
return 0;
}
``````