| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 664 人关注过本帖
标题:已知今天的日期(含年、月、日),编程求得明天的日期(含年、月、日)。
取消只看楼主 加入收藏
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
 问题点数:0 回复次数:5 
已知今天的日期(含年、月、日),编程求得明天的日期(含年、月、日)。

#include<stdio.h>
void month_nm(struct date day);
void tomorrow(struct date day);
int run(struct date day);
struct date
{
int day;
int month;
int year;
};
void main()
{
struct date day;
int a;
printf("\n以数字形式输入日期(年月日)\n");
printf("\n输入年(1900-2005):");
scanf("%d",&day.year);
fflush(stdin);
printf("\n输入月:");
scanf("%d",&day.month);
printf("\n输入日: ");
scanf("%d",&day.day);
printf("\n今天日期是:");
if((day.year>=1900)&&(day.year<=2005))
{ printf("%d年",day.year);
a=run(day);
}
else
printf("\n请输入的无效哦?");
if((day.month>=1)&&(day.month<=12))
{month_nm(day);
}
else
printf("\n请输入的无效哦?");
if((day.month==1||day.month==3||day.month==5||day.month==7||day.month==8||day.month==10||day.month==12)&&(day.day>=1&&day.day<=31))
printf("%d日",day.day);
else if ((day.month==4||day.month==6||day.month==9||day.month==11)&&(day.day>=1&&day.day<=30))
printf("%d日",day.day);
else if((day.month==2)&&(day.day>=1&&day.day<=28+a))
printf("%d日",day.day);
printf("\n明天日期是:");
tomorrow(day);
printf("\n");

}

void month_nm(struct date day)
{
switch(day.month)
{
case 1:printf("一月");break;
case 2:printf("二月");break;
case 3:printf("三月");break;
case 4:printf("四月");break;
case 5:printf("五月");break;
case 6:printf("六月");break;
case 7:printf("七月");break;
case 8:printf("八月");break;
case 9:printf("九月");break;
case 10:printf("十月");break;
case 11:printf("十一月");break;
case 12:printf("十二月");break;
}
}

int run(struct date day)
{int b;
if((day.year%4==0)&&(day.year%100!=0)||(day.year%400==0))
b=1;
else
b=0;
return b;
}

void tomorrow(struct date day)
{
struct date tomorrow;
if((day.month==1||day.month==3||day.month==5||day.month==7||day.month==8||day.month==10||day.month==12)&&(day.day<31))
{
tomorrow.day=day.day+1;
tomorrow.month=day.month;
tomorrow.year=day.year;

}
else if ((day.month==4||day.month==6||day.month==9||day.month==11)&&(day.day<30))
{
tomorrow.day=day.day+1;
tomorrow.month=day.month;
tomorrow.year=day.year;

}
else if((day.month==2)&&(day.day<(28+run(day))))
{
tomorrow.day=day.day+1;
tomorrow.month=day.month;
tomorrow.year=day.year;
}

else
{
tomorrow.month=day.month+1;
tomorrow.day=1;
tomorrow.year=day.year;
}
if(tomorrow.month>=12)
{
tomorrow.year=day.year+1;
tomorrow.month=1;
tomorrow.day=1;
}
printf("%d年",tomorrow.year);
printf("%d月",tomorrow.month);
printf("%d日",tomorrow.day);

}

搜索更多相关主题的帖子: day int date struct 
2007-10-17 23:35
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
得分:0 

求助好的C语言的算法

2007-10-17 23:36
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
得分:0 
2007-10-17 23:36
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
得分:0 
2007-10-17 23:37
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
得分:0 

#include <stdio.h>
#include <string.h>

struct date
{
int month;
int year;
int day;
};

struct date update(struct date today)
{
struct date tomorrow;
const int dayspermonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int days;
if( (today.year%4 == 0 && today.year%100 != 0) || (today.year %400 == 0 && today.month == 2))
{
days=29;
}
else
{
days=dayspermonth[today.month-1];
}
if(today.day!=days)
{
tomorrow=(struct date){today.month,today.day+1,today.year};
}
else
{
if (today.month == 12)
{
tomorrow=(struct date){1,1,today.year+1};
}
else
{
tomorrow=(struct date){today.month+1,1,today.year};
}
}
return tomorrow;
}


int main()
{
struct date thisdate,nextdate;
struct date update(struct date today);
printf("Input date's date (mm dd yyyy)");
scanf("%i:%i:%i",&thisdate.month,&thisdate.day,&thisdate.year);
nextdate = update(thisdate);
printf("%i:%i:%i",nextdate.month,nextdate.day,nextdate.year);
return 0;
}

2007-10-17 23:38
zhangwef8012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-17
收藏
得分:0 
kan bu  dong a  
2007-10-17 23:38
快速回复:已知今天的日期(含年、月、日),编程求得明天的日期(含年、月、日) ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034345 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved