C++控制台日历

初次接触C++写的,也算是编程的起点吧~

#include <iostream>
#include <iomanip>
using namespace std;
bool leapYear(int year)
{
return ((year%4==0&&year%100!=0)||year%400==0); }
int firstDayOfYear(int year)
{
long n; int i=1; n=year*365; for(i=1;i<year;i++){ if(leapYear(i))n+=1; } return n%=7; }
int main()
{
int year; int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; char week[]="Sun Mon Tue Wed Thu Fri Sat"; cout<<"Input the year you want:"; cin>>year; if(leapYear(year))
{ month[
1]=29; } else
{ month[1]=28;0 } int a,b,c,d,e; a=firstDayOfYear(year); e=a; int calendar[12][6][7]; int i,j,k; for(i=0;i<12;i++)
{
for(j=0;j<6;j++)
{
for(k=0;k<7;k++)
{ calendar[i][j][k]
=0; } } } for(d=0,b=0;d-12<0;e=(e+month[d])%7,d++){ for(c=1,b=0;month[d]-c>=0;c++)
{
if((e+c-1)%7==0)
{ b
++; } calendar[d][b][(e+c-2)%7]=c-1; } } for(i=0;i<6;i++)
{
for(int j=0;j<2;j++)
{ cout
<<setw(3)<<week<< " "; } cout<<endl; for(int k=0;k<6;k++)
{
for(int j=0;j<2;j++)
{
for(int l=0;l<7;l++)
{
if(calendar[i*2+j][k][l]==0)
{ cout
<<" "; } else
{ cout<<setw(3)<<calendar[i*2+j][k][l]<<" "; } } cout<<" "; } cout<<endl; } cout<<endl; } return 0; }
posted @ 2014-03-31 10:42  iCH1990  阅读(346)  评论(0编辑  收藏  举报