定义一个结构体变量(包括年、月、日),要求输入年月日,编写程序计算并输出该日在本年中第几天.
展开全部
// 现写的!
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef int BOOL;
int YearMouth[]={31,29,31,30,31,30,31,31,30,31,30,31,32};
typedef struct Date
{
int year;
int mouth;
int day;
}DATE;
//判断是否是瑞年
BOOL isNotRuiYear(int year)
{
BOOL flog=FALSE;
if(0==year%4 && 0==year/4%100)
flog=TRUE;
if(0==year%400)
flog=TRUE;
return flog;
}
void main()
{
DATE date;
int i;
int AllDay=0;
//提示输入年月日
printf("please input int year!\n");
scanf("%d",&date.year);
printf("please input int mouth!\n");
scanf("%d",&date.mouth);
printf("please input int day!\n");
scanf("%d",&date.day);
//计算天数
if(isNotRuiYear(date.year))
{
for(i=0;i<date.mouth;i++)
AllDay+=YearMouth[i];
AllDay-=1;
}
else
{
for(i=0;i<date.mouth;i++)AllDay+=YearMouth[i];
}
//打印结果
printf("this %d year %d mouth %d day in all year is %d days \n",date.year,date.mouth,date.day,AllDay);
}
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef int BOOL;
int YearMouth[]={31,29,31,30,31,30,31,31,30,31,30,31,32};
typedef struct Date
{
int year;
int mouth;
int day;
}DATE;
//判断是否是瑞年
BOOL isNotRuiYear(int year)
{
BOOL flog=FALSE;
if(0==year%4 && 0==year/4%100)
flog=TRUE;
if(0==year%400)
flog=TRUE;
return flog;
}
void main()
{
DATE date;
int i;
int AllDay=0;
//提示输入年月日
printf("please input int year!\n");
scanf("%d",&date.year);
printf("please input int mouth!\n");
scanf("%d",&date.mouth);
printf("please input int day!\n");
scanf("%d",&date.day);
//计算天数
if(isNotRuiYear(date.year))
{
for(i=0;i<date.mouth;i++)
AllDay+=YearMouth[i];
AllDay-=1;
}
else
{
for(i=0;i<date.mouth;i++)AllDay+=YearMouth[i];
}
//打印结果
printf("this %d year %d mouth %d day in all year is %d days \n",date.year,date.mouth,date.day,AllDay);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main()
{
struct date{
int year;
int month[12];
int day;
}_date={0,{31,28,31,30,31,30,31,31,30,31,30,31},0};
int mon,i,days=0;
scanf("%d%d%d",&_date.year,&mon,&_date.day);
if((!(_date.year%4)&&_date.year%100)||!(_date.year%400))
_date.month[1]=29;
for(i=0;i<mon-1;i++)
days+=_date.month[i];
days+=_date.day;
printf("%d\n",days);
}
我们的作业……
void main()
{
struct date{
int year;
int month[12];
int day;
}_date={0,{31,28,31,30,31,30,31,31,30,31,30,31},0};
int mon,i,days=0;
scanf("%d%d%d",&_date.year,&mon,&_date.day);
if((!(_date.year%4)&&_date.year%100)||!(_date.year%400))
_date.month[1]=29;
for(i=0;i<mon-1;i++)
days+=_date.month[i];
days+=_date.day;
printf("%d\n",days);
}
我们的作业……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |