我是靠谱客的博主 开心长颈鹿,这篇文章主要介绍从键盘输入某年某月(包括闰年),编程输出该年的该月拥有的天数,现在分享给大家,希望可以做个参考。

从键盘输入某年某月(包括闰年),编程输出该年的该月拥有的天数。

**输入格式要求:"%d,%d" 提示信息:“Input year,month:” “The number of days is %dn”
**输出格式要求:"%d"
程序运行示例1如下:
Input year,month:1984,2
The number of days is 29
程序运行示例2如下:
Input year,month:2000,2
The number of days is 29
程序运行示例3如下:
Input year,month:1985,2
The number of days is 28
程序运行示例4如下:
Input year,month:1983,13
Input year,month:1983,-1
Input year,month:1983,1
The number of days is 31

#include<stdio.h>
#define MONTHS 12

int main(void)
{
    int days[2][MONTHS] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 
	{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
    int year, month;
    do
    {
        printf("Input year,month:");
        scanf("%d,%d", &year, &month );
    }
    while (month < 1 || month > 12);
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
        printf("The number of days is %dn", days[1][month - 1]);
    else
        printf("The number of days is %dn", days[0][month - 1]);
    return 0;
}

最后

以上就是开心长颈鹿最近收集整理的关于从键盘输入某年某月(包括闰年),编程输出该年的该月拥有的天数的全部内容,更多相关从键盘输入某年某月(包括闰年),编程输出该年内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(128)

评论列表共有 0 条评论

立即
投稿
返回
顶部