您的位置:

c语言公历日期,c语言 日期

本文目录一览:

用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语言怎么编写万年历

1、首先下载安装Notepad++,这是一款免费的且能够编辑C语言的软件。

2、然后下载安装tdm-gcc,这是为了给电脑配置环境变量,以便能够编译C语言的。

3、在安装完以上两款软件后,还要配置一下环境变量。

4、然后开始编辑C语言万年历,首先要判断一个年份是闰年还是平年,用一个子程序来做:

5、然后就开始写主程序:首先用scanf得到一个年份,在判断这个年份是平年还是闰年后用printf在CMD中打出来。

6、在编写完成后,在Notepad++界面下按下F5,在输入框中输入:

cmd /k gcc -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" CLS "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" PAUSE EXIT

7、最后点击运行,会弹出CMD,在里面输入年份后回车:例如输入2017,然后回车,就会生成2017年的万年历了!

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;

}