⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctecnolagy.txt

📁 随着电子技术的迅速发展
💻 TXT
字号:
C语言写万年历 (程序源码)2007年06月11日 星期一 下午 06:54【要求】:

1. 程序运行后,首先在屏幕上显示主菜单:


1.        查询某年某月某日是星期几

2.        查询某年是否是闰年

3.        打印某年的全年日历

4.        退出


2. 在主菜单中输入1后,显示:


“请输入年月日(XXXX,XX,XX)”

运行后输出:XXXX年XX月XX日是星期X,是否继续查询(Y/N)?

如果输入Y,则重新显示 “请输入年月日(XXXX,XX,XX)”,否则回到主菜单。


3. 在主菜单中输入2后,显示:


“请输入要查哪一年?(XXXX)”

运行后输出:XXXX年是(否)是闰年,是否继续查询(Y/N)?

如果输入Y,则重新显示,“请输入要查哪一年?(XXXX)”,否则回到主菜单。


4. 在主菜单中输入3后,显示:


“请输入要打印的年份(XXXX)”

运行后输出XXXX年的日历,格式为:

XXXX

X(月数)

0    1     2     3    4     5     6

S    M    T    W    T    F     S

x    x     x    x     x     x     x

x    x     x    xx    xx    xx    xx

xx   xx    xx   xx    xx    xx    xx

xx   xx    xx   xx    xx    xx    xx

xx   xx    xx

X(月数)

0    1     2     3     4     5     6

S    M    T    W     T     F    S

x     x     x     x

x    x     x    xx   xx    xx    xx

xx   xx    xx   xx    xx    xx    xx

xx   xx    xx   xx    xx    xx    xx

xx   xx    xx   xx    xx

.


运行完后显示:“是否继续打印(Y/N)?”

如果输入Y,则重新显示,“请输入要打印的年份(XXXX)”,否则回到主菜单。

5. 在主菜单中输入4后,显示:“是否要真的退出(Y/N)?”


如果输入Y,结束程序运行,否则重新显示主菜单。



我的源码如下,编译调试通过:


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define X " Sun Mon Tue Wed Thu Fri Sat"

void menu()
{
   system("cls");
   printf("\nTHIS IS THE MENU OF THE PROGRAM !");
   printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");
   printf("\n\n");
   printf("1 Find the day by year-month-date.\n");
   printf("2 Find the year you input if the leap year.\n");
   printf("3 Print the calendar of the year you input.\n");
   printf("4 Exit.\n\n");
   printf("Input your choice:");
}

int getday(int year,int month,int date)
{
   int flag,s,i;
   int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
   int cont=0;
   flag=isleap(year);
   if(flag==1)
     a[2]++;
   for(i=1;i<month;i++)
   {
     cont=cont+a[i];
   }
   cont=cont+date;
   s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;
   return s%7;
}
int isleap(int year)
{
    if(year%4==0&&year%100||year%400==0)
     return 1;
    else
     return 0;
}
void print(int n)
{
int i;
for(i=0;i<n;i++) printf(" ");
}
int day(int year)
{
long a,b;
if(year<=2000)
{
   a=2000-year;
   b=6-(a+a/4-a/100+a/400)%7; 
   return b;
}
else 
{
   a=year-2000; 
   b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6; 
   return b%7;
}
}
void printcalendar(int year)
{
    int i,j,k,m,n,f1,f2,d;
    int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    printf("\nThe calendar of the year %d.\n\n",year);
    d=day(year);
    if(isleap(year)==1) 
     a[2]++;
    for(i=1;i<=12;i+=2)
{
   m=0; n=0; f1=0; f2=0;
   switch(i)
   {
   case 1:printf(" Januray 1    ");break;
   case 3:printf(" March 3      ");break;
   case 5:printf(" May 5        ");break;
   case 7:printf(" July 7      "); break;
   case 9:printf(" September 9 ");break;
   case 11:printf(" Nevember 11 ");break;
   }
   print(21); 
   switch(i+1)
   {
   case 2:printf(" February 2   "); break;
   case 4:printf(" April 4     "); break;
   case 6:printf(" June 6       "); break;
   case 8:printf(" August 8    ");   break;
   case 10:printf(" October 10   "); break;
   case 12:printf(" December 12"); break;
   }
   printf("\n"); 
   printf(X);  
   print(6);
   printf(X); 
   printf("\n");
   for(j=0;j<6;j++)
   {
    if(j==0)
    {
     print(d*4); 
     for(k=0;k<7-d;k++) 
     {
      printf("%4d",++m); 
     }
     print(6);
     d+=a[i]%7;
d%=7;
     print(d*4); 
     for(k=0;k<7-d;k++)
     {
      printf("%4d",++n); 
     }
     printf("\n");
    }
    else
    {
     for(k=0;k<7;k++)
     {
      if(m<a[i])
      {
       printf("%4d",++m); 
   }
      else
      {
       print(4);   
   }
      if(m==a[i]) f1=1;
     }
     print(6); 
     for(k=0;k<7;k++)
     {
      if(n<a[i+1])
      {
       printf("%4d",++n);
   }
      else
      {
       print(4); 
   }
      if(n==a[i+1]) f2=1;
     }
     printf("\n"); 
     if(f1&&f2) break;
    }
   }
   d+=a[i+1]%7; 
   d%=7; 
   printf(" "); 
   for(k=0;k<27;k++) 
   {
    printf("="); 
   }
   print(6);  
   printf(" ");  
   for(k=0;k<27;k++) 
   {
    printf("=");
   }
   printf("\n"); 
   if(i==5)
   {
    printf("Press any key to others!");
    getch();
    system("cls");
   }
}
}
void main()
{
int choice;
int year,month,date;
int day,flag;
char con;
menu();
scanf("%d",&choice);
if(choice==1) 
     {
     r1:system("cls");
       printf("\nPlease input the year-month-date(XXXX,XX,XX):");
       scanf("%d,%d,%d",&year,&month,&date);
       day=getday(year,month,date);
    if(day==0)
           printf("\n%d-%d-%d is Sunday!\n",year,month,date);
       if(day==1)
           printf("\n%d-%d-%d is Monday!\n",year,month,date);
    if(day==2)
           printf("\n%d-%d-%d is Tuesday!\n",year,month,date);
    if(day==3)
     printf("\n%d-%d-%d is Wednesday!\n",year,month,date);
    if(day==4)
     printf("\n%d-%d-%d is Thursday!\n",year,month,date);
    if(day==5)
     printf("\n%d-%d-%d is Friday!\n",year,month,date);
    if(day==6)
     printf("\n%d-%d-%d is Saturday!\n",year,month,date);
       printf("\nContinue...(Y/N)");
       con=getch();
       if((con=='y')||(con=='Y'))
     goto r1;
       if((con=='n')||(con=='N'))
         main();
     }
if(choice==2)
{
   r2:system("cls");
   printf("\nPlease input the year(XXXX):");
   scanf("%d",&year);
      flag=isleap(year);
   if(flag==1)
    printf("\nThe year %d is leap year!\n",year);
   if(flag==0)
    printf("\nThe year %d is not leap year!\n",year);
      printf("\nContinue...(Y/N)");
       con=getch();
       if((con=='y')||(con=='Y'))
     goto r2;
       if((con=='n')||(con=='N'))
         main();
}
if(choice==3)
{
     r3:system("cls");
   printf("\nPlease input the year(XXXX):");
   scanf("%d",&year);
      printcalendar(year);
      printf("Continue...(Y/N)");
       con=getch();
       if((con=='y')||(con=='Y'))
     goto r3;
       if((con=='n')||(con=='N'))
         main();
}
if(choice==4)
{
    system("cls");
    printf("\nDo you want to Exit?(Y/N)");
       con=getch();
       if((con=='y')||(con=='Y'))
     return;
       if((con=='n')||(con=='N'))
          main();
}

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -