结构体:计算输入日期是该年的第几天 C语言学渣求指导~

#include<stdio.h>structdate{intyear,month,day;};intmain(){structdatec;intyearday,tab[... #include<stdio.h>
struct date{
int year,month,day;
};
int main()
{
struct date c;
int yearday,tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
while(scanf("%d-%d-%d",&c.year,&c.month,&c.day)!=EOF)
{
yearday=0;
if((c.year%4==0)&&(c.year%100!=0))||c.year%400==0))
{
for(i=0;i<=c.month;i++)
yearday=yearday+tab[1][i];
}
else
{
for(i=0;i<=c.month;i++)
yearday=yearday+tab[0][i];
}
printf("%d\n",yearday);
}
return 0;
}
运行都运行不了。。。
展开
 我来答
育知同创教育
2016-01-30 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
展开全部
c语言计算输入日期在年份中的排序:
#include <stdio.h>

int yisleap(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

int get_yday(int mon, int day, int year)
{
static const int days[2][13] = {
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
};
int leap = yisleap(year);

return days[leap][mon] + day;
}

int main(void)
{
int day = get_yday(1, 31, 2013);

printf("%d\n", day);
return 0;
}
薇薇采儿
2016-02-04 · 知道合伙人教育行家
薇薇采儿
知道合伙人教育行家
采纳数:12216 获赞数:96302
从事高校文书学 档案学 现汉 古代汉语等专业课教学25年,曾

向TA提问 私信TA
展开全部
#include<stdio.h>
struct Student
{
int year;
int month;
int day;
};
void main()
{
int days(struct Student date);
struct Student Day;
printf("输入年月日:\n");
scanf("%d,%d,%d",&Day.year,&Day.month,&Day.day);
printf("日期%d,%d,%d是该年的第%d天\n",Day.year,Day.month,Day.day,days(Day));
}
int days(struct Student date)
{
int result=0;
switch(date.month-1)
{
case 12: result+=31;
case 11: result+=30;
case 10: result+=31;
case 9: result+=30;
case 8: result+=31;
case 7: result+=31;
case 6: result+=30;
case 5: result+=31;
case 4: result+=30;
case 3: result+=31;
case 2:
{
if(date.year%400==0||date.year%100!=0&&date.year%4==0)
result+=28;
else result+=29;
}
case 1: result+=31;
}
result+=date.day;
return result;
} 收起
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
葎僧泞梦的叹息
2015-06-14
知道答主
回答量:1
采纳率:0%
帮助的人:1239
展开全部
#include<stdio.h>
struct Student
{
int year;
int month;
int day;
};
void main()
{
int days(struct Student date);
struct Student Day;
printf("输入年月日:\n");
scanf("%d,%d,%d",&Day.year,&Day.month,&Day.day);
printf("日期%d,%d,%d是该年的第%d天\n",Day.year,Day.month,Day.day,days(Day));
}
int days(struct Student date)
{
int result=0;
switch(date.month-1)
{
case 12: result+=31;
case 11: result+=30;
case 10: result+=31;
case 9: result+=30;
case 8: result+=31;
case 7: result+=31;
case 6: result+=30;
case 5: result+=31;
case 4: result+=30;
case 3: result+=31;
case 2:
{
if(date.year%400==0||date.year%100!=0&&date.year%4==0)
result+=28;
else result+=29;
}
case 1: result+=31;
}
result+=date.day;
return result;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
时间旅者45
2015-06-11 · 超过20用户采纳过TA的回答
知道答主
回答量:55
采纳率:0%
帮助的人:35.2万
展开全部
#include<stdio.h>
#include<iostream>
using namespace std;
struct date{
int year,month,day;
};
int main()
{
struct date c;
int yearday,tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
},i;
while(scanf("%d-%d-%d",&c.year,&c.month,&c.day)!=EOF)
{
yearday=0;
if(((c.year%4==0)&&(c.year%100!=0))||c.year%400==0)
{
for(i=0;i<=c.month;i++)
yearday=yearday+tab[1][i];
}
else
{
for(i=0;i<=c.month;i++)
yearday=yearday+tab[0][i];
}
printf("%d\n",yearday);
}
return 0;
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式