| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 681 人关注过本帖
标题:代码欣赏too
只看楼主 加入收藏
剑人
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2005-9-21
收藏
 问题点数:0 回复次数:4 
代码欣赏too

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

void printmonth(int m);
void printhead(int m);
int daysofmonth(int m);
int firstday(int y);
int year,weekday;

int main()
{
int i;
cout<<"请输入您要查询的年份:";
cin>>year;
weekday = firstday(year);
cout<<endl<<endl;
cout<<" "<<year<<"年"<<endl;
for(i=1;i<=12;++i)
{
printmonth(i);
cout<<endl;
}
cout<<endl<<endl;
return 0;
}
void printmonth(int m) //打印每月日历 //重点!mvp!
{
int i ,days;
printhead(m);
days=daysofmonth(m);
for(i=1;i<=days;i++)
{
cout<<setw(8)<<i;
weekday = (weekday+1)%7;
if(weekday == 0)
cout<<endl;
}
}
void printhead(int m) //打印每月的日历头(判定起始位置)
{
int i;
cout<<endl<<m<<"月 日 一 二 三 四 五 六"<<endl;//每个字隔6个空格,每个字相当于2个空格
for(i=0;i<weekday;++i)
cout<<" "; //共8个空格。
}
int firstday(int y) //判断某年元旦是星期几
{
double s;
s = floor((double)(year-1 + (year-1)/4 - (year-1)/100 + (year-1)/400 + 1));
return (int)s%7;
}

int daysofmonth(int m) //每月的天数
{
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if ( (year%4==0 && year%100!=0 )|| (year%400 == 0) )
return 29;
else
return 28;
default:
return 0;
}
}

搜索更多相关主题的帖子: 代码 欣赏 
2006-03-22 08:20
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 
写的 还好

2006-03-22 09:23
剑人
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2005-9-21
收藏
得分:0 

解释一下:

就是输入要查询的年份,比如2004,

就ok了,答案就给出来了^_^

2006-03-22 13:42
qijingbin
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1937
专家分:0
注 册:2005-12-14
收藏
得分:0 
你最好再把阴历的日期添加进去就更好了!

Within you I lose myself, without you I find myself wanting to be lost again!!!
2006-03-24 21:57
yfcomeon
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-3-24
收藏
得分:0 


有阴历的话就更好了

2006-03-24 23:52
快速回复:代码欣赏too
数据加载中...
 
   



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

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