1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > c语言 日期 星期几 新手做的日历表及查找日期是星期几

c语言 日期 星期几 新手做的日历表及查找日期是星期几

时间:2021-08-05 15:52:34

相关推荐

c语言 日期 星期几 新手做的日历表及查找日期是星期几

该楼层疑似违规已被系统折叠隐藏此楼查看此楼

#include

#include

#include

#include void ff(char c, int n); //星号函数

int weekn(int yeah); //返回年份的一月一日是星期几

bool yeah_run(int yeah); //判断是否是闰年

int chariqi(int mon[12], int yeah, int yue, int ri); //查找日期函数

char xingqi(int xin); //查找日期是星期几 int main (void)

{

while(1){

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

int i,j, n=0, week;

int yeah, yue, ri;

puts("请输入需要打印的年份(不要早于1980年)");

scanf("%d", &yeah); system("cls");

if(yeah_run(yeah))

mon[1] = 29;

week = weekn(yeah);

ff('*', 18);

printf("%d年年历", yeah);

ff('*', 18);

putch('\n'); for(j=0; j<12; j++)

{

n=0;

putch('\n');

ff('*', 20);

printf("第%d月", j+1);

ff('*', 20);

puts("\n");

puts("星期日 星期一 星期二 星期三 星期四 星期五 星期六");

while(n

{

if(7==week)

{

week=0;

break;

}

printf(" ");

n++;

}

for(i=0; i

{

if(7==week)

{

putch('\n');

week = 0;

}

printf("%-7d", i+1);

week++;

}

}

puts("\n");

do

{

puts("请输入需要查找的月份");

scanf("%d", &yue);

puts("请输入需要查找的日期");

scanf("%d", &ri);

if(yue>12 || ri >mon[yue-1])

{

puts("您输入的日期有误,请重新输入");

}

else

break;

}

while(1);

printf("您需要查的日期是:\n%d年%d月%d日\t", yeah, yue, ri);

switch(chariqi(mon, yeah, yue, ri))

{

case 0: puts("星期日"); break;

case 1: puts("星期一"); break;

case 2: puts("星期二"); break;

case 3: puts("星期三"); break;

case 4: puts("星期四"); break;

case 5: puts("星期五"); break;

case 6: puts("星期六"); break;

default : break;

}

while(getchar()!='\n')

continue;

getch();

system("cls");

}

return 0;

}

void ff(char c, int n)

{

int i=0;

while(i

{

printf("%c", c);

i++;

}

return ;

}

int weekn(int yeah)

{

int sum =0;

int i,j;

i = yeah - 1980;

if(0==i)

return 2; j = (i-1) / 4 +1;

return (i*365+j+2)%7;

}

bool yeah_run(int yeah)

{

if(0==yeah%4 && 0!=yeah%100 || 0==yeah%400)

return true;

else

return false;

}

int chariqi(int mon[12], int yeah, int yue, int ri)

{

int duoyutian = weekn(yeah);

int i, j, sum =0;

if(yeah_run(yeah))

{

mon[1]=29;

}

for(i=0; i

sum = sum + mon[i];

sum = sum + ri +duoyutian; return sum%7-1;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。