结构体:计算输入日期是该年的第几天 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;
}
运行都运行不了。。。 展开
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;
}
运行都运行不了。。。 展开
4个回答
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;
}
#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 · 知道合伙人教育行家
关注
展开全部
#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;
} 收起
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;
} 收起
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
#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;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询