求高手编写一个万年历的C语言程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求高手编写一个万年历的C语言程序相关的知识,希望对你有一定的参考价值。
要求如下:1.查询某年某月每一天对应星期几。2.查询某年某月的上个月或下个月的日历情况。3.查询某年某月是这一年的第几天,并查询该天是星期几。4.判断该年是闰年还是平年,并判断该年的生肖。要求比较多,烦有意者发到qq:495429546上,会多追加分的,谢谢。
#include<stdio.h>#include<stdlib.h>
char* month_str[]="January","February","March","April","May","June","July","August","September","October","November","December";
char* week[]="Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday";
int IsLeapYear(int year) /*find out the year is leap year or not*/
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
int month_day(int year,int month)
int mon_day[]=31,28,31,30,31,30,31,31,30,31,30,31;
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
int DaySearch(int year,int month,int day) /*search what day this day is*/
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
int PrintAllYear(int year)/*print the all year*/
int temp;
int i,j;
printf("\n\n%d Calander\n",year);
for(i=1;i<=12;i++)
printf("\n\n%s(%d)\n",month_str[i-1],i);
printf("0 1 2 3 4 5 6 \n");
printf("S M T W T F S \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf("%d ",j-temp);
else
printf("%d ",j-temp);
if(j%7==0)
printf("\n");
return 0;
int main()
int option,da;
char ch;
int year,month,day;
printf("Copyright @ 2005 TianQian All rights reserved!:):):)");
printf("\n\nWelcome to use the WanNianLi system!\n");
while(1)
printf("\nPlease select the service you need:\n");
printf("\n1 Search what day the day is");
printf("\n2 Search whether the year is leap year or not");
printf("\n3 Print the calander of the whole year");
printf("\n4 Exit\n");
scanf("%d",&option);
switch(option)
case 1:
while(1)
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=DaySearch(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
break;
case 2:
while(1)
printf("\nPlease input the year which needs searched?(XXXX)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d is Leap year,do you want to continue?(Y/N)",year);
else
printf("\n%d is not Leap year,do you want to continue(Y/N)?",year);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
break;
case 3:
while(1)
printf("\nPlease input the year which needs printed(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
printf("\nDo you want to continue to print(Y/N)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
break;
case 4:
fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
return 0;
参考技术A 网上有很多,C语言编写的我就下载过一份,好好找一下,肯定有 参考技术B //-------------系统库定义-------------------
#include "stdio.h"
#include "Bios.h"
#include "dos.h"
#define X " Sun Mon Tue Wed Thu Fri Sat"
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define PGUP 0x4900
#define PGDW 0x5100
#define ESC 0x011b
#define QUERY 0x1071
#define QUERYD 0x1051
//--------------------------------------------
struct date dm ;//时间结构定义
int Cyear,Cmonth,Cday,Cmonnum,Lmonnum ;//全局变量
int isleap(int year)//判断闰年
if(year%4==0&&year%100||year%400==0)
return 1 ;
else
return 0 ;
int getday(int year,int month,int day)//计算X年X月X日是星期几
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+day ;
s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont ;
return s%7 ;
void printspace(int n)//输出空格
int i ;
for(i=0;i<n;i++)printf(" ");
void spacer()//输出分隔符(分隔线)
int i ;
for(i=0;i<30;i++)
printf("=");
printf("\n");
void keyinfo()//输出键盘操作信息
printf("\n-------Operation manual-------\n");
printf("Year:Up key and Down key\n");
printf("Month:Left key and Right key\n");
printf("Day:PageUp key and PageDown key\n");
printf("Query date of the calendar:Q key\n");
printf("Exit calendar:Esc key\n");
void week()//输出当前日期是星期几
int day ;
day=getday(Cyear,Cmonth,Cday);
if(day==0)
printf("\n%d-%d-%d is Sunday!\n",Cyear,Cmonth,Cday);
if(day==1)
printf("\n%d-%d-%d is Monday!\n",Cyear,Cmonth,Cday);
if(day==2)
printf("\n%d-%d-%d is Tuesday!\n",Cyear,Cmonth,Cday);
if(day==3)
printf("\n%d-%d-%d is Wednesday!\n",Cyear,Cmonth,Cday);
if(day==4)
printf("\n%d-%d-%d is Thursday!\n",Cyear,Cmonth,Cday);
if(day==5)
printf("\n%d-%d-%d is Friday!\n",Cyear,Cmonth,Cday);
if(day==6)
printf("\n%d-%d-%d is Saturday!\n",Cyear,Cmonth,Cday);
void calendar(int year,int month,int day)//显示日历
int i,j,d,m,flag,week;
int a[13]=0,31,28,31,30,31,30,31,31,30,31,30,31;
m=0,d=0,week=0;
Cmonnum=a[month];//当前月的天数
Lmonnum=a[month-1];//上一月的天数
week=d=getday(year,month,1);//取得X年X月的1日是星期几
flag=isleap(year);
if(flag==1)
a[2]++;
clrscr();
printf("\n The calendar of year %d\n",year);
spacer();
switch(month)
case 1 :
printf(" January 1 ");
break ;
case 2 :
printf(" February 2 ");
break ;
case 3 :
printf(" March 3 ");
break ;
case 4 :
printf(" April 4 ");
break ;
case 5 :
printf(" May 5 ");
break ;
case 6 :
printf(" June 6 ");
break ;
case 7 :
printf(" July 7 ");
break ;
case 8 :
printf(" August 8 ");
break ;
case 9 :
printf(" September 9 ");
break ;
case 10 :
printf(" October 10 ");
break ;
case 11 :
printf(" Nevember 11 ");
break ;
case 12 :
printf(" December 12");
break ;
printf("\n");
printf(X);
printf("\n");
for(i=0;i<6;i++)
if(i==0)//如果是第一个星期时,执行!
printspace(d*4);
for(j=0;j<7-d;j++)
if(m==day-1)//m到达day的前一天时,输出[%d]
printf(" [%d]",++m);
else if(m==day && week!=0)//m到达当天时的,输出%3d
printf("%3d",++m);
else
printf("%4d",++m);
week=(week<6)?week+1:0;//计算当天是星期几
printf("\n");
else//不是第一个星期时,执行!
for(j=0;j<7;j++)
if(m<a[month])
if(m==day-1)//m到达day的前一天时,输出[%d]
if(m<9)//代表只有一位数的数字如9,8,7.....等。
printf(" [%d]",++m);
else//代表只有两位数的数字如10,11,12.....等。
printf(" [%d]",++m);
else if(m==day && week!=0)
printf("%3d",++m);
else
printf("%4d",++m);
week=(week<6)?week+1:0;//计算当天是星期几
printf("\n");
if(m==a[month])break ;
spacer();
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);
week();
printf("\nThe current date is: %d-%d-%d\n",dm.da_year,dm.da_mon,dm.da_day);
keyinfo();
//keyboard Operation
void key()
int key ;
Cyear=dm.da_year,Cmonth=dm.da_mon,Cday=dm.da_day ;
calendar(Cyear,Cmonth,Cday);
while(1)
key=bioskey(0);
if(key==RIGHT)
if(Cmonth<12&&Cmonth>=1)
Cmonth++;
else
Cyear++;
Cmonth=1 ;
if(key==LEFT)
if(Cmonth<=12&&Cmonth>1)
Cmonth--;
else
Cyear--;
Cmonth=12 ;
if(key==UP)
Cyear++;
if(key==DOWN)
Cyear--;
if(key==PGUP)
if(Cday!=1)
Cday--;
else if(Cday==1&&Cmonth==1)
Cyear--;
Cmonth=12 ;
Cday=31 ;
else
Cmonth--;
Cday=Lmonnum ;
if(key==PGDW)
if(Cmonnum!=Cday)
Cday++;
else if(Cmonnum==Cday&&Cmonth==12)
Cyear++;
Cmonth=1 ;
Cday=1 ;
else
Cmonth++;
Cday=1 ;
if(key==QUERY||key==QUERYD)
printf("Input date format(YYYY,MM,DD):");
scanf("%d,%d,%d",&Cyear,&Cmonth,&Cday);
if(key==ESC)break ;
calendar(Cyear,Cmonth,Cday);
void main()
clrscr();
getdate(&dm);
key();
急切求高手编写一个 java程序,大体是关于IO流的文件拷贝
内容是 D盘下面有一个文件a ,E盘下有一个文件b,a里面有内容 b里面是空的,然后把a的内容拷贝到b里面去,再想办法 读取a的内容。先感谢各位大哥大姐
你好,再想办法 读取a的内容。这个是不必要的,从a拷贝到b就是读取的过程,代码如下:import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
import java.io.Writer;
public class ReaderDemo02
public static void main(String args[]) throws Exception File f1= new File("d:" + File.separator + "a.txt") ;
File f2= new File("e:" + File.separator + "b.txt") ;
Reader input = null ; // 准备好一个输入的对象
Writer out = null ; // 准备好一个输出的对象
input = new FileReader(f1) ;
out = new FileWriter(f2) ;
char c[] = new char[1024] ; // 所有的内容都读到此数组之中
int temp = 0 ; // 接收每一个内容
int len = 0 ; // 读取内容
while((temp=input.read())!=-1)
out.write(temp) ; //写入b
c[len] = (char)temp ;
len++ ;
input.close() ;
out.close() ;
System.out.println("内容为:" + new String(c,0,len)) ;//输出a的内容
; 参考技术A 这个玩意儿,如果学过java就不是问题。如果做单纯的应用还是vb更好。
以上是关于求高手编写一个万年历的C语言程序的主要内容,如果未能解决你的问题,请参考以下文章