自己试着做了个万年历,挺好玩的!!

代码如下:

//*******万年历
#include "pch.h"
#include <iostream>
using namespace std;
bool isleap(int year);//判断平润年
int week_of_new_year_day(int year);//判断星期几
int main()
{
	int year,month,day,weekday;
	cout << "请输入年份:\n";
	cin >> year;
	cout << "\n     ********  " << year << " *******\n";
	weekday = week_of_new_year_day(year);
	for (month=1; month<=12; month++)
	{
		cout << "\n                " << month <<"月"<< endl;
		cout << "---------------------------------------|\n";
		cout << "Sun   Mon   Tue   Wed   Thu   Fri   Sat|\n";
		cout << "---------------------------------------|\n";
		for (int j = 0; j < weekday; j++)
		{
			cout << "      ";
		}
			if (month == 4 || month == 6 || month == 9 || month == 11)
			day = 30;
			else if (month == 2)
			{
				if (isleap(year))   day = 29;
				else  day = 28;
			}
			else day = 31;
			for (int i = 1; i <= day; i++)
			{
				if (i <= 9) cout << " " << i<<"    ";
				else cout << i<<"    ";
				weekday++;
				if (weekday==7)
				{
					weekday = 0;
					cout << "\n";
				}
			}
			cout << "\n";
	}
	return 0;
}
bool isleap(int year)
{
	bool  k=0;
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		k = 1;
	return  k;
}
int  week_of_new_year_day(int year)
{
	int n;
	n = year - 1900;
	n = n + (n -1)/4 + 1;
	n = n % 7;
	return n;
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值