#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;

    //1 2 4 7
    //3 5 8 10
    //6 9 11 12

    for(int k=0; k<n + m -1; k++){
        for(int i=0; i<n; i++){
            int j = k-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;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: