定义一个结构体变量(包括年月日),计算改日在当年中是第几天?运行后不是想要的结果
c程序源代码如下:但运行后不是想要的结果,暂时找不到原因:#include<stdio.h>#include<stdlib.h>typedefstruct{intmont...
c程序源代码如下:但运行后不是想要的结果,暂时找不到原因:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int month;
int day;
int year;
}DATE;
DATE date;
int main(int argc, char *argv[])
{
int days;
printf("please input the date:\n");
scanf("%d,%d,%d",&date.year,&date.month,&date.day);
switch(date.month)
{
case 1:
days = date.day;
break;
case 2:
days = date.day + 31;
break;
case 3:
days = date.day + 31 + 28;
break;
case 4:
days = date.day + 31 + 28 +31;
break;
case 5:
days = date.day + 31 + 28 + 31 + 30;
break;
case 6:
days = date.day + 31 + 28 + 31 + 30 + 31;
break;
case 7:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30;
break;
case 8:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31;
break;
case 9:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
break;
case 10:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
break;
case 11:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
break;
case 12:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
break;
}
if (date.year%4 == 0 && date.year%100 != 0 || date.year%400 == 0)
{
if(date.month >= 3)
{
days += 1;
}
printf("\nthe day in this year is the %dth day!\n",days);
}
system("PAUSE");
return 0;
} 展开
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int month;
int day;
int year;
}DATE;
DATE date;
int main(int argc, char *argv[])
{
int days;
printf("please input the date:\n");
scanf("%d,%d,%d",&date.year,&date.month,&date.day);
switch(date.month)
{
case 1:
days = date.day;
break;
case 2:
days = date.day + 31;
break;
case 3:
days = date.day + 31 + 28;
break;
case 4:
days = date.day + 31 + 28 +31;
break;
case 5:
days = date.day + 31 + 28 + 31 + 30;
break;
case 6:
days = date.day + 31 + 28 + 31 + 30 + 31;
break;
case 7:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30;
break;
case 8:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31;
break;
case 9:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
break;
case 10:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
break;
case 11:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
break;
case 12:
days = date.day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
break;
}
if (date.year%4 == 0 && date.year%100 != 0 || date.year%400 == 0)
{
if(date.month >= 3)
{
days += 1;
}
printf("\nthe day in this year is the %dth day!\n",days);
}
system("PAUSE");
return 0;
} 展开
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
展开全部
if (date.year%4 == 0 && date.year%100 != 0 || date.year%400 == 0)
{
if(date.month >= 3)
{
days += 1;
}
printf("\nthe day in this year is the %dth day!\n",days);
}
改成
if (date.year%4 == 0 && date.year%100 != 0 || date.year%400 == 0)
{
if(date.month >= 3)
{
days += 1;
}
}
printf("\nthe day in this year is the %dth day!\n",days);
{
if(date.month >= 3)
{
days += 1;
}
printf("\nthe day in this year is the %dth day!\n",days);
}
改成
if (date.year%4 == 0 && date.year%100 != 0 || date.year%400 == 0)
{
if(date.month >= 3)
{
days += 1;
}
}
printf("\nthe day in this year is the %dth day!\n",days);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询