养成好习惯,点个赞 再走;有问题,欢迎私信、评论,我看到都会回复的
- 一年12个月
- 2月是个特殊的(闰年有29天,否则有28天)
- 1,3,5,7,8,10,12月有31天(口诀:一三五鸡八死了),12月又称为腊月
- 其余有30天
- 判断闰年很简单(口诀:4年一闰,百年不闰,四百必闰)
文章目录
- 输入一个年份和一个月份,输出该年此月天数
- 用结构体存放日期,计算该日是本年的第几天
输入一个年份和一个月份,输出该年此月天数
#include <>
int main()
{
int year, month, day;
//请输入一个年份和一个月份
scanf("%d%d", &year, &month);
printf("year = %d, month= %d\n", year, month);
if(1 <= month && month <= 12){
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8 :
case 10:
case 12:day = 31; break;
case 4:
case 6:
case 9:
case 11:day = 30; break;
case 2:
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) day = 29;
else day = 28;
}
printf("此年的此月有%d天", day);
}
else printf("请确认你输入的值有实际意义");
return 0;
}
输入:2020 2
输出:
year = 2020, month= 2
此年的此月有29天
用结构体存放日期,计算该日是本年的第几天
注意:此题中switch对break的使用思路和上题不同
#include<>
struct date{
int year;
int month;
int day;
}date1;
int main()
{
int f(int, int, int);
//输入年、月、日
scanf("%d%d%d", &date1.year, &date1.month, &date1.day);
f(date1.year, date1.month, date1.day);
return 0;
}
int f(int i, int j, int k)
{
int flag = 0, a = 0;//flag用来判定闰年
if((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) flag = 1;
switch(j-1)
{
case 11:a += 30;
case 10:a += 31;
case 9 :a += 30;
case 8 :a += 31;
case 7 :a += 31;
case 6 :a += 30;
case 5 :a += 31;
case 4 :a += 30;
case 3 :a += 31;
case 2 :a += 28+flag;
case 1 :a += 31; break;
default :printf("please input others\n");
}
a += k;
printf("this is the %d day of %d year\n", a, i);
}
输入:2020 3 5
输出:
this is the 65 day of 2020 year
C语言入门题目文章导航:
- 素数(C)
- 水仙花数(C)
- 斐波那契数列(C)
- 完数(C)
- 阶乘(C)
- 直角杨辉三角形(C)
- 大写字母、小写字母、ASCII码(C)
- 输入一个字符,找出他的前驱字符和后继字符(C)
- 最大数、最小数(C)
- 百钱买百鸡(C语言,枚举法)
- 辗转相除法求最大公约数,利用最大公约数求最小公倍数(C)
- 本篇文章
- 输入一个不多于4位的正整数,求它的位数,并按逆序输出各位数字(C)
- 利用二维数组求方阵的主次对角线之和(C)
- 在一个二维数组中找出最小数及其所在的行和列(C)
- 找出一个二维数组中的鞍点(C)
- 删除指定字符串的指定字符(C)
- 字符串(C)
- 条件判断语句1(C)
- 条件判断语句2(C)
- 圆、三角形、正方形、长方体、计算1到100的和、和差积商、平均值
- 输入三个整数,要求程序把数据按从小到大的顺序放入x y z中,然后输出(C)
- 18个数围成一圈,求相邻三数之和最大数(C)
- 梯形法求定积分(C)
- 学生与课程的综合问题(C)