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

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

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