您的位置:

c语言公历,c语言日历程序

本文目录一览:

能不能帮我用c语言写下准确公历的计算程序

if(month==4||6||9||11)

if(month==1||3||5||7||8||10||12)

这种写法是错误的。

应该这样写

if(month==4||month==6||month==9||month==11)

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)

另外,其实你可以不这么写,太多了,可以用

switch..case

switch(month)

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

day=31;break;

case 4:

case 6:

case 9:

case 11:

day=30;break;

case 2:

if()...

(c语言实现)打印指定年份的公历表和农历表

#include stdlib.h

#include stdio.h

#include conio.h

int IsLeapYear(int);

main()

{

int i;

int day;

int year;

int temp;

int temp_i;

long int Year_days = 0;

int Year_Start = 1;

int Per_Year_Days;

int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};

printf("输入年份: "); /*从键盘输入年份*/

scanf("%d",year);

while(Year_Start year)

{

if( IsLeapYear( Year_Start ) ) /*判断输入的年份是否为闰年*/

Per_Year_Days = 366;

else

Per_Year_Days = 365;

Year_days = Year_days + Per_Year_Days;

Year_Start++;

} /*这个while循环计算从1到输入的年份共有多少天*/

for( temp = 1; temp =12; temp++ )

{ /*这个for循环打印出该年每个月的日历*/

switch( temp )

{

case 1:

printf(" January(%d)\n",year);

break;

case 2:

printf(" February(%d)\n",year);

break;

case 3:

printf(" March(%d)\n",year);

break;

case 4:

printf(" April(%d)\n",year);

break;

case 5:

printf(" May(%d)\n",year);

break;

case 6:

printf(" June(%d)\n",year);

break;

case 7:

printf(" July(%d)\n",year);

break;

case 8:

printf(" August(%d)\n",year);

break;

case 9:

printf(" September(%d)\n",year);

break;

case 10:

printf(" October(%d)\n",year);

break;

case 11:

printf(" November(%d)\n",year);

break;

case 12:

printf(" December(%d)\n",year);

break;

}

i = Year_days % 7;

printf("Mon Tue Wed Thu Fri Sat Sun\n");

if( i != 0 )

for( temp_i = 0; temp_i i; temp_i++)

printf(" ");

day = 1;

if( IsLeapYear(year) temp == 2) /*如果是闰年的2月*/

while( day = month_day[12] )

{

if( day 1 )

if( Year_days % 7 == 0 )

printf("\n");

if( day = 10 )

printf("%-4d",day);

else

printf("%-4d",day);

Year_days++;

day++;

}

else /*不是闰年*/

while (day = month_day[temp-1])

{

if( day 1 )

if( Year_days % 7 == 0 )

printf("\n");

if( day =10 )

printf("%-4d",day);

else

printf("%-4d",day);

Year_days++;

day++;

}

printf("\n");

if( getch() == 'q' ) /*输入Q结束*/

exit(0);

}

getch();

}

int IsLeapYear( int year ) /*判断是否为闰年*/

{

if ((year %4 == 0) (year % 100 != 0) ||

(year % 400 == 0) )

return 1;

else

return 0;

}

用C语言怎么将公历日期转化为农历日期?

其实很简单,你的程序中定义一些数组,保存一些重要参数即可,下面是JAVASCRIPT的,看懂了你就可以用C来写:

var lunarInfo=new Array(

0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,

0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,

0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,

0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,

0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,

0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,

0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,

0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,

0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,

0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,

0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,

0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,

0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,

0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,

0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0)

//====================================== 传回农历 y年的总天数

function lYearDays(y) {

var i, sum = 348

for(i=0x8000; i0x8; i=1) sum += (lunarInfo[y-1900] i)? 1: 0

return(sum+leapDays(y))

}

//====================================== 传回农历 y年闰月的天数

function leapDays(y) {

if(leapMonth(y)) return((lunarInfo[y-1900] 0x10000)? 30: 29)

else return(0)

}

//====================================== 传回农历 y年闰哪个月 1-12 , 没闰传回 0

function leapMonth(y) {

return(lunarInfo[y-1900] 0xf)

}

//====================================== 传回农历 y年m月的总天数

function monthDays(y,m) {

return( (lunarInfo[y-1900] (0x10000m))? 30: 29 )

}

C语言编写 年历显示程序

此题不是很难,我会前三个

关键是算那一年的第一天是周几

给你个基本算法,一年是365天,闰年366天

364是7的倍数,这样一年多出一天,中间多少个闰年,在加上相应的天数即可

400年多出来的天数是400+97=497也是7的倍数,那么400年一轮回,这样就算400年以内的即可

一个子函数,返回这一年的第一天是周几,很好做

int ye(int year)

{

int y=year%400;

int day=y;

int i;

for(i=0;iy;i++)

if(闰年判断)

day++;

return day%7;

}

做一个月份天数的全局数组

int mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};

需要时用一个if判断闰年改变m0[1]的值是28还是29

打印子函数,有一个小技巧,就是每个月前面的空缺部分,这个1月份是ye子函数的返回值,后面的你看和前面月份是不是重合啊,吧这个记录下来在下一月份用即可

1 2

3 4

这样月份排列更好打印一些,你的那个截图有点麻烦

int pr(int year)

{

int k=ye(year);

int i,j,;

if(闰年判断)

mo[1]=29;

else

mo[1]=28;

for(i=0;i12;i++)

{

printf("周几英文的打印");

for(j=0;jk;j++)

printf("一般是四个空格,就是月份前面空缺的打印");

for(j=1;j=mo[i];j++)

{

printf("%4d",j);

k++;

if((k+j)%7==0)

printf("\n");

}

k%=7;

if(k!=0)

printf("\n");

}

}

如果像你那样,感觉需要赋值一个大一点的数组,在吧数组打印出来更好,呵呵

c语言 万年历的程序设计

#include windows.h

#include winnt.h

#includeiostream

#includeiomanip

using namespace std;

int week(int,int,int); //根据年月日判断星期几

int leap_year(int); //判断闰年

void display_year(int ); //显示某年日历

void demand_day(int,int,int); //查询某天

int main()

{

int y,m,d,es=1;

while(es)

{

HANDLE consolehwnd;

consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(consolehwnd,12);

cout"请选择操作:\n1→显示某年日历\

\n2→查询某天\n0→退出"endl;

char tp[20];cintp;

if(tp[1]!='\0'||tp[0]'2'||tp[0]'0'){cout"输入有误"endl;continue;}

switch(tp[0]-48)

{

case 1:{cout"请输入年份:";ciny;system("cls");display_year(y);break;}

case 2:{cout"请输入年、月、日,以空格分开:";cinymd;system("cls");

demand_day(y,m,d);break;}

case 0:{es=0;break;}

}

}

return 0;

}

//-----根据年月日判断星期几-------------------------

int week(int y,int m, int d)

{

int week1,yy=y;

if(m==1) {m=13;yy--;}

if(m==2) {m=14;yy--;}

week1=(d+2*m+3*(m+1)/5+yy+yy/4-yy/100+yy/400)%7;

int s;

switch (week1)

{

case 0: s=1; break;

case 1: s=2; break;

case 2: s=3; break;

case 3: s=4; break;

case 4: s=5; break;

case 5: s=6; break;

case 6: s=0; break;

}

return s;

}

//----判断闰年-------------------------------------

int leap_year(int y)

{

int i;

if((y%4==0y%100!=0)||y%400==0)i=1;

else i=0;

return i;

}

//--------显示某年日历------------------------

void display_year(int y)

{

int n1,n2,i,j,a[13],c,d;

HANDLE consolehwnd;

consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(consolehwnd,5);

coutsetw(38)y"年"endl;

coutsetw(28)"*********";

for(i=1;i=27;i++)cout'*';

coutendl;

a[1]=a[3]=a[5]=a[7]=a[8]=a[10]=a[12]=31;//

a[4]=a[6]=a[9]=a[11]=30; //确定每月天数

if(leap_year(y))a[2]=29;

else a[2]=28; //

for(i=1;i=11;i+=2) //六次循环

{

SetConsoleTextAttribute(consolehwnd,1);

coutsetw(14)i"月"setw(42)i+1"月"endl;

SetConsoleTextAttribute(consolehwnd,2);

coutsetw(4)"日"setw(4)"一"setw(4)"二"setw(4)"三"setw(4)\

"四"setw(4)"五"setw(4)"六";

coutsetw(16)' ';

coutsetw(4)"日"setw(4)"一"setw(4)"二"setw(4)"三"setw(4)\

"四"setw(4)"五"setw(4)"六"endl;

SetConsoleTextAttribute(consolehwnd,7);

n1=week(y,i,1);n2=week(y,i+1,1);

if(n1) //-----------

{

for(j=1;j=n1;j++) //

coutsetw(4)' ';

}

for(j=1;j=7-n1;j++)

coutsetw(4)j;

coutsetw(16)' ';

if(n2)

{ //-----输出每次循环的第一行---

for(j=1;j=n2;j++)

coutsetw(4)' ';

}

for(j=1;j=7-n2;j++)

coutsetw(4)j;

coutendl; //--------------

c=8-n1;d=8-n2;

for(int m=1;m6;m++) //每月日历最多占六行

{

if(ca[i])coutsetw(4*7)' ';//若ca[i],则该月的这一行全部输出空格

for(j=c;j=a[i];j++)

{

coutsetw(4)j;

if((j-c+1)%7==0){c=j+1;break;}

if(j==a[i]){coutsetw((6-week(y,i,a[i]))*4)' ';c=j+1;break;}

//如果j是该月最后一天,该行剩下的全部补空格

}

coutsetw(16)' ';

if(da[i+1])coutsetw(4*7)' ';

for(j=d;j=a[i+1];j++)

{ //

coutsetw(4)j;

if((j-d+1)%7==0){d=j+1;break;}

if(j==a[i+1]){coutsetw((6-week(y,i+6,a[i+1]))*4)' ';d=j+1;break;}

}

coutendl;

}

coutendl;

}

coutendl;

}

//--------查询某天------------

void demand_day(int y,int m,int d)

{

int n;

HANDLE consolehwnd;

consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(consolehwnd,5);

n=week(y,m,d);

switch(n)

{

case 1:couty"年"m"月"d"日"",""星期一"endl;break;

case 2:couty"年"m"月"d"日"",""星期二"endl;break;

case 3:couty"年"m"月"d"日"",""星期三"endl;break;

case 4:couty"年"m"月"d"日"",""星期四"endl;break;

case 5:couty"年"m"月"d"日"",""星期五"endl;break;

case 6:couty"年"m"月"d"日"",""星期六"endl;break;

case 0:couty"年"m"月"d"日"",""星期日"endl;break;

default:break;

}

coutendl;

}