• 날짜 계산 프로그램
  • [레벨:18]Zappy (IP: *.41.220.199)
    조회 수: 25175, 2010-05-09 13:50:57(2010-05-09)
  • #include <stdio.h>

    int main( void )
    {
    int i;
    int all_day = 0;
    int first_year, first_month, first_day;
    char *date[7] = { "일", "월", "화", "수", "목", "금", "토" };
    int result;

    /* Input */
    printf("Enter the Year: ");
    scanf("%d", &first_year );
    printf("Eter the Month: ");
    scanf("%d", &first_month );
    printf("Enter the day: ");
    scanf("%d", &first_day );

    /* Sum of year */
    for( i = 1; i < first_year; i++ )
    {
    if( ((i%4==0) && (i%100!=0)) || (i%400==0) )
    all_day += 366;
    else
    all_day += 365;
    }

    /* Sum of month */
    for( i = 1; i < first_month; i++ )
    {
    if( i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12 )
    all_day += 31;
    else if( i != 2 )
    all_day += 30;
    else
    {
    if( ((first_year%4==0) && (first_year%100!=0)) || (first_year%400==0) )
    all_day += 29;
    else
    all_day += 28;
    }
    }

    /* Sum of day */
    all_day += first_day;

    /* Output */
    result = all_day % 7;
    printf("\n\n********************* week decision ******************\n");
    printf("%d년 %d월 %d일은 %d일 째이고 %s요일입니다.\n", first_year, first_month, first_day, all_day, date[result] );

    return 0;
    }

댓글 0

번호 제목 닉네임 조회  등록일 
[레벨:18]Zappy 25175 2010-05-09
21 Zappy 12416 2007-03-25
20 Zappy 6069 2007-03-21
19 Zappy 10543 2007-03-21
18 Zappy 7955 2006-10-25
17 Zappy 9142 2006-10-25
16 Zappy 12224 2006-10-25
15 Zappy 7915 2006-10-25
14 Zappy 60142 2006-10-25
13 Zappy 9221 2006-10-25
XE Login