#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int n,m;
scanf("%d %d", &n, &m);
int **arr = (int**)malloc(n * sizeof(int*));
for(int i=0; i<n; i++){
arr[i] = (int*)malloc(m * sizeof(int));
}
int a = 1;
//6 9 11 12
//3 5 8 10
//1 2 4 7
//(0,0)(0,1)(0,2)(0,3)
//(1,0)(1,1)(1,2)(1,3)
//(2,0)(2,1)(2,2)(2,3)
//0 1 2 3
//1 2 3 4
//2 3 4 5
for(int k=0; k<n + m -1; k++){
for(int i=n-1; i>=0; i--){
int j = k-(n-1-i);
if(j>=0 && j<m){
arr[i][j] = a;
a++;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: