게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
반복문 하나로 동적으로 다이아몬드 출력하기
게시물ID : programmer_12814짧은주소 복사하기
작성자 : 반복문
추천 : 2
조회수 : 1819회
댓글수 : 20개
등록시간 : 2015/08/19 15:44:37
옵션
  • 창작글
  • 외부펌금지
https://web.archive.org/web/20150819064024/http://www.todayhumor.co.kr/board/view.php?table=programmer&no=12810
http://www.todayhumor.co.kr/board/view.php?table=programmer&no=12810

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

int main() {
        int N;
        scanf("%d", &N);
        char *W, *S;
        W = (char*)calloc((2*N-1)+1, sizeof(char));
        S = (char*)calloc((N-1)+1, sizeof(char));
        memset(W, ' ', (N-1));
        memset(S, '*', (2*N-1));
        int i=0;
        for(i=0; i<2*N-1; i++) {
            int x = (i < N) ? i : (2*(N-1) - i);
            int w = N - 1 - x;
            int s = x * 2 + 1;
            printf("%s", W + N-1 - w);
            printf("%s\n", S + 2*N-1 - s);
        }
        free(W);
        free(S);
}

왜 안된다고 하시는지 모르겠네요.
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호