2 답변

  • 아래 코드를 응용해 보세요.

    from math import cos, sin, pi
    
    def det_func(x, y):
        rs = [ (cos(2*i*pi/5), sin(2*i*pi/5)) for i in range(5)]
        sign = 1
        for r in rs:
            if r[0]*x + r[1]*y < 8:
                sign *= -1
        return sign
    
    SIZE = 25
    
    for y in range(-SIZE, SIZE):
        for x in range(-SIZE, SIZE):
            c =  " " if det_func(x, y) > 0 else "x"
            print(c, end=" ")
        print()
    
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x 
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x     x x x x x x x x x x x x x x x x x
      x x x x x x x x x x x x x x x x x x x x x x x x x x x x x       x x x x x x x x x x x x x x x x x 
        x x x x x x x x x x x x x x x x x x x x x x x x x x x         x x x x x x x x x x x x x x x x x
          x x x x x x x x x x x x x x x x x x x x x x x x x x         x x x x x x x x x x x x x x x x x
          x x x x x x x x x x x x x x x x x x x x x x x x x           x x x x x x x x x x x x x x x x x 
    x x     x x x x x x x x x x x x x x x x x x x x x x x             x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x             x x x x x x x x x x x x x x x x x
    x x x x x       x x x x x x x x x x x x x x x x x x               x x x x x x x x x x x x x x x x x
    x x x x x x           x x x x x x x x x x x x x x                 x x x x x x x x x x x x x x x x x 
    x x x x x x x               x x x x x x x x x x                   x x x x x x x x x x x x x x x x x
    x x x x x x x x                     x x x x x x                   x x x x x x x x x x x x x x x x x
    x x x x x x x x                           x x                     x x x x x x x x x x x x x x x x x
    x x x x x x x x x                           x x                   x x x x x x x x x x x x x x x x x 
    x x x x x x x x x x                       x x x x x x             x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x                     x x x x x x x x x       x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x                   x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 
    x x x x x x x x x x x x               x x x x x x x x x x x x x x       x x x x x x x x x x x x x x
    x x x x x x x x x x x x x             x x x x x x x x x x x x x x             x x x x x x x x x x x 
    x x x x x x x x x x x x x           x x x x x x x x x x x x x x x                   x x x x x x x x
    x x x x x x x x x x x x x x       x x x x x x x x x x x x x x x x                         x x x x x
    x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x                               x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x                               x x
    x x x x x x x x x x x x x x       x x x x x x x x x x x x x x x x                         x x x x x
    x x x x x x x x x x x x x           x x x x x x x x x x x x x x x                   x x x x x x x x 
    x x x x x x x x x x x x x             x x x x x x x x x x x x x x             x x x x x x x x x x x
    x x x x x x x x x x x x               x x x x x x x x x x x x x x       x x x x x x x x x x x x x x
    x x x x x x x x x x x                   x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x                     x x x x x x x x x       x x x x x x x x x x x x x x x x x 
    x x x x x x x x x x                       x x x x x x             x x x x x x x x x x x x x x x x x
    x x x x x x x x x                           x x                   x x x x x x x x x x x x x x x x x
    x x x x x x x x                           x x                     x x x x x x x x x x x x x x x x x
    x x x x x x x x                     x x x x x x                   x x x x x x x x x x x x x x x x x 
    x x x x x x x               x x x x x x x x x x                   x x x x x x x x x x x x x x x x x
    x x x x x x           x x x x x x x x x x x x x x                 x x x x x x x x x x x x x x x x x 
    x x x x x       x x x x x x x x x x x x x x x x x x               x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x             x x x x x x x x x x x x x x x x x
    x x     x x x x x x x x x x x x x x x x x x x x x x x             x x x x x x x x x x x x x x x x x 
          x x x x x x x x x x x x x x x x x x x x x x x x x           x x x x x x x x x x x x x x x x x
          x x x x x x x x x x x x x x x x x x x x x x x x x x         x x x x x x x x x x x x x x x x x
        x x x x x x x x x x x x x x x x x x x x x x x x x x x         x x x x x x x x x x x x x x x x x
      x x x x x x x x x x x x x x x x x x x x x x x x x x x x x       x x x x x x x x x x x x x x x x x 
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x     x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x   x x x x x x x x x x x x x x x x x
    x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
    
  • 단순히 출력만한다면 이렇게합니다.

    #include <stdio.h>
    int main() {
        printf("\n");
        //위부분
        for (int i=3; i <= 4; i++) {
            for (int j=0; j < 6 - i; j++) {
                printf(" ");
            }
            for (int j=0; j < i * 2 + 1; j++) {
                printf("*");
            }
            printf("\n");
        }
        //아래부분
        for (int i=1; i <= 6; i++) {
            for (int j=0; j < i; j++) {
                printf(" ");
            }
            for (int j=0; j < (6 - i) * 2 + 1; j++) {
                printf("*");
            }
            printf("\n");
        }
        return 0;
    }
    

답변을 하려면 로그인이 필요합니다.

Hashcode는 개발자들을 위한 무료 QnA 사이트입니다. 계정을 생성하셔야만 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)

ᕕ( ᐛ )ᕗ
로그인이 필요합니다

Hashcode는 개발자들을 위한 무료 QnA사이트 입니다. 계정을 생성하셔야만 글을 작성하실 수 있습니다.