c语言返回星期几的函数,c语言求几天后是星期几

c语言计算日期为星期几

#includestdio.h

创新互联公司专注于宜君网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供宜君营销型网站建设,宜君网站制作、宜君网页设计、宜君网站官网定制、成都小程序开发服务,打造宜君网络公司原创品牌,更为您提供宜君网站排名全网营销落地服务。

int isRn(int num){

if((num%4==0num%400!=0)||num%400==0){

return 1;

}else{

return 0;

}

int monthDay(int year,int month){

if(month==1||month==3||month==5

||month==7||month==8||month==10

||month==12){

return 31;

}else if(month==4||month==6||month==9

||month==11)

{

return 30;

}else if(month==2){

if(isRn(int num)==1){

return 29;

}else{

return 28;

}

}

}

void main(){

int sum=0,year,month,day,i,temp,j;

printf("请输入年份:");

scanf("%d",year);

while(year1900){

printf("年份必须从1900年开始!\n\n");

printf("请输入年份:");

scanf("%d",year);

}

printf("请输入月份:");

scanf("%d",month);

while(month1||month12){

printf("月份必须是1到12之间!\n\n");

printf("请输入月份:");

scanf("%d",month);

}

printf("请输入日:");

scanf("%d",day);

while(daymonthDay(year,month)||day1){

printf("日必须从1开始,并且不能大于该月的天数!\n\n");

printf("请输入日:");

scanf("%d",day);

}

temp=month;

temp-=1;

for(i=1900;i=year;i++){

for(j=1;j=12;j++){

if(i==yearj==temp){

break;

}

sum+= monthDay(year,j);

}

}

sum+=day;

printf("%d年%d月%d日,是星期",year,month,day)

if(sum%7==0){

printf("日。\n");

}else if(sum%7==1){

printf("一。\n");

}else if(sum%7==2){

printf("二。\n");

}else if(sum%7==3){

printf("三。\n");

}else if(sum%7==4){

printf("四。\n");

}else if(sum%7==5){

printf("五。\n");

}else if(sum%7==2){

printf("六。\n");

}

}

C语言:输入任意年月日,求该天是星期几?

注意:本源码中,函数GetWeekDay的返回值仅仅表示输入参数是否“正确/有效”(例如前三个参数使用2001,2,29就是无效参数),能否得到预期的星期值;真正的星期值则是通过输出变量返回给主调函数的。

#include

time.h

#include

stdio.h

int

GetWeekDay(int

nYear,int

nMon,int

nDay,

int

*npWeekDay);

int

main()

{

int

nMyWeekDay;

int

nResult;

nResult

=

GetWeekDay(2007,1,10,nMyWeekDay);

return

0;

}

//输入日期,返回星期的C语言函数

int

GetWeekDay(int

nYear,int

nMon,int

nDay,

int

*npWeekDay)

{

int

nRetVal

=

0;

time_t

tMyDateTime;

struct

tm

tmMyDate,*tmpMyDate;

if((nYear1900||nYear=3000)

||

(nMon1

||

nMon12)

||

(nDay1||nDay31)

)

{

nRetVal

=

1;

*npWeekDay

=

-1;

return

nRetVal;

}

//memset(tmMyDate,0,sizeof(struct

tm));

tmMyDate.tm_year

=

nYear-1900;

tmMyDate.tm_mon

=

nMon-1;

tmMyDate.tm_mday

=

nDay;

tmMyDate.tm_hour

=16;

tmMyDate.tm_min

=30;

tmMyDate.tm_sec

=30;

tMyDateTime

=

mktime(tmMyDate);

if(tMyDateTime0)

{

nRetVal

=

1;

*npWeekDay

=

-1;

return

nRetVal;

}

tmpMyDate

=

localtime(tMyDateTime);

*npWeekDay

=

tmpMyDate-tm_wday;

return

nRetVal;

}

c语言:用自定义函数来实现任意输入一个日期,结果输出其星期几

y年m月d日,是第几天days啊?计算方法:days=mon[1]+mon[2]+.+mon[m-1]+d;mon[i]是第i个月的天数;同时要注意,mon[2]闰年29,否则28;给出代码吧,虽然这样对你其实么有什么好处、#includeintmain(){intmon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};inty,m,d,days;intleap,i;scanf("%d%d%d",y,m,d);for(i=1,days=0;i2)days++;printf("days=%d\n",days);}自己读,自己写,经常百度,不好~~~刚才有个单词打错了,sorry、、~~


分享标题:c语言返回星期几的函数,c语言求几天后是星期几
网页网址:http://pwwzsj.com/article/dsgcppd.html