/编写一个程序,提示用户输入日,月和年。月份可以是月份号,月份名和月份名缩写。
然后该程序返回一年中到用户指定日子(包括着一天)的总天数/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//月份结构 数字、全称、缩写、当月天数
struct month {
char number[3];
char months[20];
char monthss[4];
int days;
};
//初始化月份结构
struct month years[12] = {
{“1”,“January”,“juy”,31},
{“2”,“February”, “feb”,28},
{“3”,“March”,“mar”,31},
{“4”,“April”,“apr”,30},
{“5”,“May”,“may”,31},
{“6”,“June”,“jun”,30},
{“7”,“July”,“jul”,31},
{“8”,“August”,“aug”,31},
{“9”,“September”,“sep”,30},
{“10”,“October”,“oct”,31},
{“11”,“November”,“nov”,30},
{“12”,“December”,“dec”,31},
};
int main(void)
{
char fname[20];
int day,year,total,i,n;
puts(“请按照顺序输入日、月份、年份。”);
puts(“月份输入可以是数字、全称和缩写。”);
puts(“日期输入-1,结束循环。”);
while(scanf("%d %s %d",&day,fname,&year)==3 && day>0)
{
<

该程序使用C语言实现,让用户输入日、月、年,并根据输入判断月份和日期的合法性。程序能处理月份的数字、全称和缩写形式,同时考虑闰年的2月天数。用户输入-1结束循环,输出截止用户指定日期的当年总天数。
最低0.47元/天 解锁文章
781

被折叠的 条评论
为什么被折叠?



