显示单月的日历的C程序

题目如下:

要求显示出单月的日历,用户说明这个月的天数和本月的起始日是星期几,即可输出该月的日历。

就是这么一道简单的程序,我憋了两天总算弄出来了,结果虽然达到了要求,但距离我预想的还有一段差距,先把程序

代码放在上面,希望大家多提修改意见。

 

/***********************************************************
 * Name: date.c
 * Purpose: Print the month day
 * Author: zimo
 * Date:01/25/2010
 * *********************************************************/

#include<stdio.h>

int main(void)
{
    int week, month, temp;

    printf("Enter number of days in month:");
    scanf(" %d", &month);
    printf("Enter starting day of the week (1=sun,7=sat):");
    scanf(" %d", &week);

 

   if(month==28||month==29||month==30||month==31)

{

   switch(week)
    {
        case 0:
            printf("Please enter the correct weekdaty! /n");
            break;
        case 1:
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 7 || temp == 14 ||
                        temp == 21 ||temp == 28)
                    printf("/n");
                else
                    printf(" %3d",temp);
            }
            printf("/n");
            break;
        case 2:
            printf("   ");
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 6 || temp == 13 ||
                        temp == 20 || temp ==27)
                    printf("%3d /n",temp);
                else
                    printf("%3d", temp);
            }
            printf("/n");
            break;
        case 3:
            printf("      ");
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 5 || temp == 12 ||
                        temp == 19 || temp == 26)
                    printf("%3d /n",temp);
                else
                    printf("%3d",temp);
            }
            printf("/n");
            break;
        case 4:
            printf("         ");
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 4 || temp ==11 ||
                        temp ==18 || temp ==25)
                    printf("%3d /n",temp);
                else
                    printf("%3d",temp);
            }
            printf("/n");
            break;
        case 5:
            printf("            ");
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 3 || temp == 10 ||
                        temp == 17 || temp ==24)
                    printf("%3d /n",temp);
                else
                    printf("%3d",temp);
            }
            printf("/n");
            break;
        case 6:
            printf("               ");
            for(temp =1; temp <= month; temp++)
            {
                if(temp == 2 || temp == 9 ||
                        temp ==16 || temp ==23)
                    printf("%3d /n",temp);
                else
                    printf("%3d", temp);
            }
            printf("/n");
            break;
        case 7:
            printf("                  ");
            for(temp = 1; temp <= month; temp++)
            {
                if(temp == 1 || temp == 8 ||
                        temp == 15 || temp == 22)
                    printf("%3d /n",temp);
                else
                    printf("%3d",temp);
            }
            printf("/n");
            break;
        default:
            printf("Illegal enter!/n");
    }
}

else

printf("ERROR!!!/n");
    return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值