중첩반복문 - 중첩반복문 활용예제6(순서바꿔 출력하기)

2018. 7. 8. 11:26algorithm/dimigo.goorm.io

#include <stdio.h>


int main() {

int num, i, j, level = 0, result = 0, tmp;

scanf("%d", &num);

for (i = 1; i <= num; i++) {

if (level == 0) {

for (j = 1; j <= num; j++) {

result++;

printf("%2d ", result);

}

level = 1;

}

else if (level == 1) {

result += num;

tmp = result;

for (j = num; j >= 1; j--) {

printf("%2d ", tmp);

tmp--;

}

level = 0;

}

printf("\n");

}

return 0;

}