#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int arr[100][100] = {0};
    int n,m;
    
    scanf("%d %d", &n, &m);
    
    int a = 1;
    
    for(int i=n-1; i>=0; i--){
        if(i % 2 ==0){
            for(int j=m-1; j>=0; j--){
                // arr[i][j] = a++;
                arr[i][j] = n*m - (m*i + j);
            }
        }else{
            for(int j=0; j<m; j++){
                // arr[i][j] = a++;
                arr[i][j] = n*m - (m*i + (m-1-j));
            }
        }
    }

    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: