| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1550 人关注过本帖, 1 人收藏
标题:请各位帮忙解释一下这段源代码 希望能详细的解释 谢谢!!
只看楼主 加入收藏
hunterwolf
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-6-25
收藏(1)
 问题点数:0 回复次数:18 
请各位帮忙解释一下这段源代码 希望能详细的解释 谢谢!!
请各位帮忙解释一下这段源代码 希望能详细的解释
#include<stdio.h>
#include<stdlib.h>

char* month_str[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};


int IsLeapYear(int year)  /*find out the year is leap year or not*/
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;

}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);

}
int DaySearch(int year,int month,int day) /*search what day this day is*/
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}

int PrintAllYear(int year)/*print the all year*/
{
int temp;
        int i,j;
printf("\n\n%d Calander\n",year);
for(i=1;i<=12;i++)
{
printf("\n\n%s(%d)\n",month_str[i-1],i);
printf("0    1    2    3    4    5    6    \n");
printf("S    M    T    W    T    F    S    \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf("     ");
else if(j-temp<10)
printf("%d    ",j-temp);
else
printf("%d   ",j-temp);

if(j%7==0)
printf("\n");
}
}
return 0;
}

int main()
{
        int option,da;
char ch;
int year,month,day;
printf("\nWelcome to use the WanNianLi system\n");

while(1)
{
printf("\nPlease select the service you need:\n");
    printf("\n1 Search what day the day is");
    printf("\n2 Search whether the year is leap year or not");
    printf("\n3 Print the calander of the whole year");
    printf("\n4 Exit\n");
scanf("%d",&option);


switch(option)
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
    scanf("%d,%d,%d,%c",&year,&month,&day);
da=DaySearch(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
                                fflush(stdin);
                                scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2:
while(1)
{
printf("\nPlease input the year which needs searched?(XXXX)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d is Leap year,do you want to continue?(Y/N)",year);
else
printf("\n%d is not Leap year,do you want to continue(Y/N)?",year);
                                fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 3:
while(1)
{
printf("\nPlease input the year which needs printed(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
printf("\nDo you want to continue to print(Y/N)?");
                                fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 4:
                        fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}

}

return 0;
}
搜索更多相关主题的帖子: 源代码 解释 
2008-06-25 11:51
liyanhong
Rank: 3Rank: 3
来 自:水星
等 级:禁止访问
威 望:8
帖 子:1867
专家分:0
注 册:2008-5-3
收藏
得分:0 
自己看不懂  直接PASS

爱上你 是 我的错  可是离 开  又舍不得  听着你为我写的歌     好难过
如果说 我说如果  我们还 能  重新来过   不去计 较 谁对谁错  会怎么做
2008-06-25 12:00
orzorz
Rank: 1
等 级:新手上路
帖 子:99
专家分:0
注 册:2008-6-25
收藏
得分:0 
想要注释,是吧?
找我QQ: 724393224
2008-06-25 14:32
hunterwolf
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-6-25
收藏
得分:0 
注释关键的几句也可以...谢谢各位了!
2008-06-25 22:45
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
万年历啊……
这东西,最省力的方法是打表……
当然LZ这种也不错……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-06-25 22:55
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
这个程序大概是打印全年的日历,查看今天日期,查看今年是不是闰年。

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2008-06-25 23:58
hunterwolf
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-6-25
收藏
得分:0 
楼上说的非常正确
因为这是我以为朋友做的,所以有几处我不太明白。
比如:int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
}

int DaySearch(int year,int month,int day) /*search what day this day is*/
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
不太明白...希望各位高手能讲解一下
2008-06-26 08:56
lai832
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-6-10
收藏
得分:0 
程序有BUG
大家试运行,打印2099年的日历
问题应该在:
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
(还在改运算中:)
2008-06-26 09:49
hunterwolf
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-6-25
收藏
得分:0 
我刚发现...那请问楼上如何改正呢?谢谢!
2008-06-26 13:12
hunterwolf
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-6-25
收藏
得分:0 
不知道从多少年之后就开始不对了...大家能否帮忙改正呢?
2008-06-26 13:13
快速回复:请各位帮忙解释一下这段源代码 希望能详细的解释 谢谢!!
数据加载中...
 
   



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

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