概述:一个可以搜索一年或一月的日历
详细功能
菜单功能,用户决定是否退出
![](https://i-blog.csdnimg.cn/blog_migrate/002c995bead1e594d45b31f3596c9506.png)
搜索一年日历功能
![](https://i-blog.csdnimg.cn/blog_migrate/81e561884744a3efde92587123fcff33.png)
搜索一月日历功能
![](https://i-blog.csdnimg.cn/blog_migrate/a5b38139a21f07a33eadd6427067aa1d.png)
每个输入进行范围合法检测
#include<bits/stdc++.h>
using namespace std;
int main()
{
int year=0,month=0,day=0,d2=0,a;
printf("1. Search year\n2. Search month\n3. Quit\nplease enter your choice\n");
cin>>a;
while(a>=4||a<=0){
printf("please enter right num\n1. Search year\n2. Search month\n3. Quit\nplease enter your choice\n");
cin>>a;
}
if(a==1){
printf("please input year(>=1900):");
cin>>year;
while(year<=1900){
printf("please enter right num");
cin>>year;
}
month=1;
while(month<=12){
if(month==1){
printf("\t\tJanuary\n");
}
if(month==2){
printf("\t\tFebruary\n");
}
if(month==3){
printf("\t\tMarch\n");
}
if(month==4){
printf("\t\tApril\n");
}
if(month==5){
printf("\t\tMay\n");
}
if(month==6){
printf("\t\tJune\n");
}
if(month==7){
printf("\t\tJuly\n");
}
if(month==8){
printf("\t\tAugust\n");
}
if(month==9){
printf("\t\tSeptember\n");
}
if(month==10){
printf("\t\tOctober\n");
}
if(month==11){
printf("\t\tNovember\n");
}
if(month==12){
printf("\t\tDecember\n");
}
printf("\n-----------------------------------------------\n");
printf(" 一\t二\t三\t四\t五\t六\t日\n");
printf("-----------------------------------------------\n");
for (int i=1900;i<year;i++)
{
if ((i%4==0&&i%100==0)||(i%400==0))
{
day+=366;
}
else
{
day+=365;
}
}
for (int m=1;m<=month;m++)
{
switch (m)
{
case 4:
case 6:
case 9:
case 11:
d2=30;
break;
case 2:
if ((year%4==0&&year%100==0)||(year%400==0))
{
d2=29;
}
else
{
d2=28;
}
break;
default:
d2=31;
break;
}
if (m<month)
{
day+=d2;
}
}
int t=day%7;
for (int i=0;i<t;i++)
{
printf("\t");
}
for (int i=1;i<=d2;i++)
{
printf("%d\t",i);
if ((i+day)%7==0)
{
printf("\n");
}
}
printf("\n");
month++;
day=0;
}
}
if(a==2){
printf("please input year(>=1900):");
cin>>year;
while(year<=1900){
printf("please enter right num");
cin>>year;
}
printf("\nplease input month([1,12]):");
cin>>month;
while(month!=1&&month!=2&&month!=3&&month!=4&&month!=5&&month!=6&&month!=7&&month!=8&&month!=9&&month!=10&&month!=11&&month!=12){
printf("please enter right num\n");
cin>>month;
}
if(month==1){
printf("\t\tJanuary\n");
}
if(month==2){
printf("\t\tFebruary\n");
}
if(month==3){
printf("\t\tMarch\n");
}
if(month==4){
printf("\t\tApril\n");
}
if(month==5){
printf("\t\tMay\n");
}
if(month==6){
printf("\t\tJune\n");
}
if(month==7){
printf("\t\tJuly\n");
}
if(month==8){
printf("\t\tAugust\n");
}
if(month==9){
printf("\t\tSeptember\n");
}
if(month==10){
printf("\t\tOctober\n");
}
if(month==11){
printf("\t\tNovember\n");
}
if(month==12){
printf("\t\tDecember\n");
}
printf("\n-----------------------------------------------\n");
printf(" 一\t二\t三\t四\t五\t六\t日\n");
printf("-----------------------------------------------\n");
for (int i=1900;i<year;i++)
{
if ((i%4==0&&i%100==0)||(i%400==0))
{
day+=366;
}
else
{
day+=365;
}
}
for (int m=1;m<=month;m++)
{
switch (m)
{
case 4:
case 6:
case 9:
case 11:
d2=30;
break;
case 2:
if ((year%4==0&&year%100==0)||(year%400==0))
{
d2=29;
}
else
{
d2=28;
}
break;
default:
d2=31;
break;
}
if (m<month)
{
day+=d2;
}
}
int t=day%7;
for (int i=0;i<t;i++)
{
printf("\t");
}
for (int i=1;i<=d2;i++)
{
printf("%d\t",i);
if ((i+day)%7==0)
{
printf("\n");
}
}
printf("\n");
return 0;
}
if(a==3){
return 0;
}
}