定义一个结构体变量,其成员包括年,月,日,计算该日
2018-06-16
展开全部
#include"stdio.h"
void main()
{
struct date
{ int year, month, day;} aday;
int i, n=0;
{
scanf("%d/%d/%d\n", &aday.year, &aday.month, &aday.day);
for (i=1;i<aday.month;i++)
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:n+=31;break;
case 4:
case 6:
case 9:
case 11:n+=30;break;
case 2:if(aday.year%4==0&&aday.year%100!=0||aday.year%400==0)
n+=29;
else
n+=28;
}
n+=aday.day;
printf("%d\n",n);
}
}
void main()
{
struct date
{ int year, month, day;} aday;
int i, n=0;
{
scanf("%d/%d/%d\n", &aday.year, &aday.month, &aday.day);
for (i=1;i<aday.month;i++)
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:n+=31;break;
case 4:
case 6:
case 9:
case 11:n+=30;break;
case 2:if(aday.year%4==0&&aday.year%100!=0||aday.year%400==0)
n+=29;
else
n+=28;
}
n+=aday.day;
printf("%d\n",n);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
struct
{ int year;
int month;
int day;
}date;
int main()
{int i,days;
int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("input year,month,day:");
scanf("%d %d %d",&date. year,&date.month,&date.day);
days=0;
for(i=1;i<date.month;i++)
days=days+day_tab[i];
days=days+date.day;
if((date.year%4==0 && date.year%100!=0 || date.year%400==0) && date.month>=3)
days=days+1;
printf("%d/%d is the %dth day in %d.\n",date.month,date.day,days,date.year);
return 0;
}
struct
{ int year;
int month;
int day;
}date;
int main()
{int i,days;
int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("input year,month,day:");
scanf("%d %d %d",&date. year,&date.month,&date.day);
days=0;
for(i=1;i<date.month;i++)
days=days+day_tab[i];
days=days+date.day;
if((date.year%4==0 && date.year%100!=0 || date.year%400==0) && date.month>=3)
days=days+1;
printf("%d/%d is the %dth day in %d.\n",date.month,date.day,days,date.year);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-06-30
展开全部
C语言实现如下:
#include<stdio.h>
void main()
{
struct day
{
int year;
int month;
int date;
}d;//定义结构体变量d。
scanf("%d%d%d",&d.year,&d.month,&d.date);/*输入年、月、日。
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int i,days=0;
if ((d.year%400==0)||(d.year%100!=0)&&(d.year%4==0)) m[1]++;
for(i=0;i<d.month-1;i++)
days+=m[i];
days+=d.date;
printf("%d\n",days);//输入该日在本年中是第几天。
}
#include<stdio.h>
void main()
{
struct day
{
int year;
int month;
int date;
}d;//定义结构体变量d。
scanf("%d%d%d",&d.year,&d.month,&d.date);/*输入年、月、日。
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int i,days=0;
if ((d.year%400==0)||(d.year%100!=0)&&(d.year%4==0)) m[1]++;
for(i=0;i<d.month-1;i++)
days+=m[i];
days+=d.date;
printf("%d\n",days);//输入该日在本年中是第几天。
}
追问
大哥。不行啊。运行有22个错误
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询