Rohyoohyun / C

0 stars 0 forks source link

1470 [기초-배열연습] 2차원 배열 지그재그 채우기 2-3(codeup) #50

Open Rohyoohyun opened 2 months ago

Rohyoohyun commented 2 months ago
#include <stdio.h>
int main(){
    int arr[101][101];
    int n, x = 1, i, j;
    scanf("%d", &n);

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

    for(i=1; i<=n; i++, puts(""))
        for(j=1; j<=n; j++)
            printf("%d ", arr[i][j]);

    return 0;
}