1. 不能被100整除但能被4整除
2. 能并橡被400整掘蔽慎除
C语言条件描述:
(year%400==0||(year%4==0&&year%100!=0)) //闰年为1,平年为0
源程序代码如下:
#include <iostream>
using namespace std
int main()
{
int year, month//定义年份月份
double a, b, c//用于判断的变量
cout <<"请输入年份 月份:"//文字提示输入年份月份
cin >>year >>month//输入年份月份
a = year % 4//能否被4整除
c = year % 100//能否被100整除
b = year % 400//能否被400整除
if (((a == 0) &&(c != 0)) || (b == 0))//判断
{
switch (month)//大月1357811
case 1:
case 3:
case 5:
case 7:
case 9:
case 11:
{
cout <<"本月有31天" <<endl
break
}
switch (month)//小月4681012
case 4:
case 6:
case 8:
case 10:
case 12:
{
cout <<"本月有30天" <瞎中<endl
break
}
switch (month)//判断闰年否
case 2:
{
cout <<"本月有29天" <<endl
break
}
}
else
{
switch (month)//大月1357811
case 1:
case 3:
case 5:
case 7:
case 9:
case 11:
{
cout <<"本月有31天" <<endl
break
}
switch (month)//小月4681012
case 4:
case 6:
case 8:
case 10:
case 12:
{
cout <<"本月有30天" <<endl
break
}
switch (month)//判断闰年否
case 2:
{
cout <<"本月有28天" <<磨皮山 endl
break
}
}
return 0
}
程序运行结果如下:
扩展资料:
其他实现方法:
#include stdio.h
#include stdlib.h
void main()
{
int year, month, days
printf(输入年份:)
scanf(%d,year)
printf(输入月份:)
scanf(%d, month)
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31
break
case 4:
case 6:
case 9:
case 11:
days=30
breakcase 2:
if(year%4==0 year%100!=0 || year%400==0// 判断闰年
days=29
else days=28
break
default:
printf(月份输入错握颂误!\n)
exit(1)
break}
printf(天数:%d\n, days)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)