ABOUT ME

https://github.com/chongin12 chongin12@naver.com

Today
Yesterday
Total
  • Layer7_20160321수업
    예제/Layer7_20160321 2016. 3. 22. 22:47
    반응형

    Example_1:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <stdio.h>
     
    int main(){
        int i, k, input;
        scanf("%d", &input);
     
        for(i=1; i<=input*input; ++i){
            
            printf("%3d", i);
            if(i%input==0){
                printf("\n");
            }
        }
    }
    cs
    input : 3

    1 2 3

    4 5 6

    7 8 9


    Example_2:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <stdio.h>
     
    int main(){
        int i, k, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(k=0; k<input; k++){
                printf("%3d", i+input*k);
            }
            printf("\n");
        }
    }
    cs
    input : 3

       1   4   7

       2   5   8

       3   6   9


    Example_3:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <stdio.h>
     
    int main(){
        int i, k, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(k=1; k<=input; ++k){
                printf("*");
            }
            printf("\n");
        }
    }
    cs
    input : 3

    ***

    ***

    ***


    Example_4:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    #include <stdio.h>
     
    int main(){
        int i, k, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(k=1; k<=input; ++k){
            if(   (k>=2&&k<=input-1)  &&  ( (i>1)&&(i<input) )   ){
                    printf(" ");
            }
                else
                    printf("*");
            }
            printf("\n");
        }
    }
    cs
    input : 3

    ***

    * *

    ***


    Example_5:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    #include <stdio.h>
     
    int main(){
        int i, j, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(j=1; j<=input; ++j){
                if( ((i==j)||(i==input-j+1)||((i==1)||(i==input)))||(j==1)||(j==input) ){
                    printf("*");
                }
                else
                    printf(" ");
            }
            printf("\n");
        }
    }
    cs


    input : 7

    *******

    **   **

    * * * *

    *  *  *

    * * * *

    **   **

    *******


    Example_6:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    #include <stdio.h>
     
    int main() {
        int i, j, k, input;
     
        scanf("%d", &input);
     
        for (i = 1; i <= input; ++i) {
            if(i==(input+1)/2){ //중간줄
                for(k=1; k<=input; ++k){
                    printf("*");    
                }
                printf("\n");
                continue//아래 for문 무시하려고
            }
            for (j = 1; j <= input; ++j) {
                if (      (i == j) || (i == input - j + 1|| (i == 1|| (i == input)  || (j == 1|| (j == input) || (j == (input+1)/2)     ) {
                    printf("*");
                }
                /*
                if문 안에 있는 것들 정리.
                    1. i==j             : 대각선_왼쪽 위에서 오른쪽 아래로
                    2. i==input-j+1  : 대각선_왼쪽 아래에서 오른쪽 위로
                    3. i==1             : 겉의 사각형_첫번째 행은 모두 *로 채운다.
                    4. i==input          : 겉의 사각형_마지막 행은 모두 *로 채운다.
                    5. j==1              : 겉의 사각형_각 행의 첫번째는 모두 *로 채운다.
                    6. j==input         : 겉의 사각형_각 행의 마지막은 모두 *로 채운다.
                    7. j==(input+1)/2: 중앙을 가로지르는 세로선_각 행의 중간부분은 *로 채운다.
                */
                else
                    printf(" ");
            }
            printf("\n");
        }
    }
    cs

    input : 17

    *****************

    **      *      **

    * *     *     * *

    *  *    *    *  *

    *   *   *   *   *

    *    *  *  *    *

    *     * * *     *

    *      ***      *

    *****************

    *      ***      *

    *     * * *     *

    *    *  *  *    *

    *   *   *   *   *

    *  *    *    *  *

    * *     *     * *

    **      *      **

    *****************


    Example_7:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    #include <stdio.h>
     
    int main(){
        int i, k, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(k=1; k<=i; ++k){
                printf("*");
            }
            printf("\n");
        }
    }
     
    cs

    input : 3

    *

    **

    ***


    Example_8:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <stdio.h>
     
    int main(){
        int i, j, input;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(j=input-i; j>=0--j){
                printf("*");
            }
            printf("\n");
        }
    }
    cs

    input : 3

    ***

    **

    *


    Example_9:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #include <stdio.h>
     
    int main(){
        int i, j, input, space;
     
        scanf("%d", &input);
     
        for(i=1; i<=input; ++i){
            for(space=0; space<input-i; ++space){
                    printf(" ");
            }
            for(j=1; j<=i; ++j){
                printf("*");
            }
            printf("\n");
        }
    }
    cs

    input : 3

      *

     **

    ***


    Example_10:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #include <stdio.h>
     
    int main() {
        int i, j, input, space;
     
        scanf("%d", &input);
     
        for (i = 0; i <= input; ++i) {
            for (space=input-i; space<input; ++space) {
                printf(" ");
            }
            for (j=0; j<input-i; ++j) {
                printf("*");
            }
            printf("\n");
        }
    }
    cs

    input : 3

    ***

     **

      *


    Example_11:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #include <stdio.h>
     
    int main(){
        int i, j, input, space;
     
        scanf("%d", &input);
     
        for(i=0; i<(input+1)/2++i){
            for(space=0; space<(input-1)/2-i; ++space){
                printf(" ");
            }
            for(j=0; j<(i+1)*2-1++j){//i를 0으로 초기화 시켰기 때문에 +1을 시켜줌.
                printf("*");
            }
            printf("\n");
        }
    }
    cs

    input : 5

       *

     ***

    *****


    Example_12:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    #include <stdio.h>
     
    int main() {
        int i, j, input, space;
     
        scanf("%d", &input);
     
        for (i = 0; i<input; ++i) {
            if(i<=(input-1)/2){
                for (space = 0; space<(input - 1/ 2 - i; ++space) {
                    printf(" ");
                }
                for (j = 0; j<(i + 1* 2 - 1++j) {//i를 0으로 초기화 시켰기 때문에 +1을 시켜줌.
                    printf("*");
                }
                printf("\n");
            }
            else{
     
                for (space=i-(input+1)/2+1; space>0--space) {
                    printf(" ");
                }
                for (j=(input-i)*2-1; j>0--j) {
                    printf("*");
                }
                printf("\n");
            }
        }
    }
    cs

    input : 5

      *

     ***

    *****

     ***

      *


    반응형

    댓글

Designed by Tistory.