#include
void main()
{
int year=0,month=0,day=0,i=0,sum=0;
while(1)
{
printf("请输入年份:");
scanf("%d",&year);
printf("请输入月份:");
scanf("%d",&month);
printf("请输入日期:");
scanf("%d",&day);
i=0; //i变量是为了控制月和日的格式是否输入正确;
switch(month) //判断每个月的日期是否输入正确;
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(day>0&&day<=31)
{
i=1;
}
break;
case 4:
case 6:
case 9:
case 11:
if(day>0&&day<=30)
{
i=1;
}
break;
case 2: //2月闰年可以输入29日;
if((year%4==0&&year%100!=0)||year%400==0)
{
if(day>0&&day<=29)
{
i=1;
}
}
else
{
if(day>0&&day<=28)
{
i=1;
}
}
break;
default: //如果输入不是1-12月份,那么月份输入有误;
i=0;
break;
}
if(i) //如果i变量为1,那么输入正确,否则重新输入;
{
break;
}
else
{
printf("请输入正确的年月日!!!\n");
}
}
i=0;
switch(month) //把每个月的日期累加;
{
case 12:
i=i+30;
case 11:
i=i+31;
case 10:
i=i+30;
case 9:
i=i+31;
case 8:
i=i+31;
case 7:
i=i+30;
case 6:
i=i+31;
case 5:
i=i+30;
case 4:
i=i+31;
case 3:
if((year%4==0&&year%100!=0)||year%400==0)
{
i=i+29;
}
else
{
i=i+28;
}
case 2:
i=i+31;
case 1:
;
}
sum=i+day;
printf("%d年%d月%d日是%d年的第%d天\n!",year,month,day,year,sum);
}
拓展资料
C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。
尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
请分别输入年月日三个数值,计算出这是这一年的第几天?
(提示:要考虑闰年和2月的情况)
*/
#include
void main()
{
int year=0,month=0,day=0,i=0,sum=0;
while(1)
{
printf("请输入年份:");
scanf("%d",&year);
printf("请输入月份:");
scanf("%d",&month);
printf("请输入日期:");
scanf("%d",&day);
i=0; //i变量是为了控制月和日的格式是否输入正确;
switch(month) //判断每个月的日期是否输入正确;
if(day>0&&day<=28)
{
i=1;
}
}
break;
default: //如果输入不是1-12月份,那么月份输入有误;
i=0;
break;
}
if(i) //如果i变量为1,那么输入正确,否则重新输入;
{
break;
}
else
{
printf("请输入正确的年月日!!!\n");
}
}
sum=i+day;
printf("%d年%d月%d日是%d年的第%d天\n!",year,month,day,year,sum);
}
#include
struct tian
{
int year;
int month;
int day;
};
int days(int year,int month,int day)
{
int s=0,i,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(year%4==0&&year%100!=0||year%400==0)
a[2]=29;
for(i=1;i
s=s+day;
return s;
}
void main()
{
int k=0;
struct tian a;
printf("输入年月日:");
scanf("%d%d%d",&a.year,&a.month,&a.day);
k=days(a.year,a.month,a.day);
printf("%d年%d月%d日是第%d天\n",a.year,a.month,a.day,k);
}
求采纳!!
#include
int main()
{
int year,month,day,sum=0,i,j;
int a[][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
scanf(%d-%d-%d",&year,&month,&day);
i=(year%4==0&&year%400!=0||year%400==0)
for(j=0;j
sum=sum+day;
printf("%d",sum);
}
有问题欢迎提出
Console.WriteLine("年");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("月");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("日");
int c = Convert.ToInt32(Console.ReadLine());
int[] d = new int[12] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int[] e = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int[] f = new int[12];
int g = 0;
if (a % 4 == 0)
{
if (a % 100 == 0)
{
if (a % 400 == 0)
{
f = d;
}
else
{
f = e;
}
}
else
{
f = d;
}
}
else
{
f = e;
}
if (b == 0 || b > 12)
{
Console.WriteLine("月份输入错误");
}
else if (c == 0 || c > f[b - 1])
{
Console.WriteLine("这个月没有这一天");
}
else
{
for (int i = 0; i < b - 1; i++)
{
g += f[i];
}
g += c;
}
Console.WriteLine(a + "年" + b + "月" + c + "日是该年的第" + g + "天");