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

int main() {
    int arr[100][100] = {0};
    int n;
    int a = 1;

    scanf("%d", &n);

    for(int i=0; i<n; i++){
        if(i % 2 ==0){
            for(int j=0; j<n; j++){
                arr[i][j] = a++;
            }
        }else{
            for(int j=n-1; j>=0; j--){
                arr[i][j] = a++;
            }
        }
    }

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