资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言星期函数编程,c语言根据日期算星期几

C语言,输入年月日,输出星期几

#includestdio.h

创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站制作、格尔木网络推广、成都微信小程序、格尔木网络营销、格尔木企业策划、格尔木品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供格尔木建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

#define SIZE 31

void inputCheck(int,int,int);

int leaYear(int);

main()

{

int year,month,day,d1,result,sum=0;

scanf("%d%d%d",year,month,day);

inputCheck(year,month,day);

for(;year1; year--)

{

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

sum+=366;

else

sum+=365;

}

d1=leaYear(month);

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

{

result=(sum+d1+day)%7;}

else

{ if(month2)

result=(sum+d1+day-1)%7;

else result=(sum+d1+day)%7;

}

switch(result)

{

case 1:printf("Monday\n");break;

case 2:printf("Tuesday\n");break;

case 3:printf("Wedensday\n");break;

case 4:printf("Thurfay\n");break;

case 5:printf("Friday\n");break;

case 6:printf("Saturday\n");break;

case 7:printf("Sunday\n");break;

}

return 0;

}

int leaYear(int m)

{

int t=0;

for(; m1;m--)

{

switch(m)

{

case 2:

t+=29;

break;

case 4:

case 6:

case 9:

case 11:

t+=30;

break;

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

t+=31;break;

}

}

return t;

}

void inputCheck(int year,int month,int day)

{

if(year0)

printf("input is wrong!\n");

else

{

switch(month)

{

case 2:

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

printf("input is wrong!\n");

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

printf("input is wrong!\n");break;

case 4:

case 6:

case 9:

case 11:

if(day30)

printf("input is wrong!\n");break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

if(day31)

printf("input is wrong!\n");

}

}

}

感觉应该加上判断输入数据是否合格的函数,即便没这个要求,我用测试数据1900 1 1试了试,我的结果是星期一,你的错误你来找吧

c语言 switch函数 星期几后面多少天是星期几

#includestdio.h

int main()

{

int a,b,c;

scanf("%d,%d",a,b);

c=(a+b)%7;//求模,这个比较方便

switch(c)

{

case 1:

printf("星期一\n");

break;

case 2:

printf("星期二\n");

break;

case 3:

printf("星期三\n");

break;

case 4:

printf("星期四\n");

break;

case 5:

printf("星期五\n");

break;

case 6:

printf("星期六\n");

break;

case 0:

printf("星期天\n");

break;

}

return 0;

}

用c语言调用函数编程,1990年1月1日是星期一 要求输入某年某月某日,输出它是星期几

这个是1984年1月1日是星期日的,你先看看,我再帮你改,最好自己能看懂

#include stdio.h

void main()

{

int year,month,day;

int tempmonth,yearday;

int week,weekday;

unsigned int sum=0;

int tag=0;

printf("输入年、月、日:\n");

scanf("%d %d %d",year,month,day);

tag =( year - 1980 )/4;

sum=(year-1984)*365 + tag;

tempmonth = month - 1;

yearday = 0;

switch(tempmonth)

{

case 12:yearday+=31;

case 11:yearday+=30;

case 10:yearday+=31;

case 9:yearday+=30;

case 8:yearday+=31;

case 7:yearday+=31;

case 6:yearday+=30;

case 5:yearday+=31;

case 4:yearday+=30;

case 3:yearday+=31;

case 2:yearday+=28;

case 1:yearday+=31;

}

yearday = yearday+day;

if ((year-1984)%4==0 month 2)

{

yearday+=1;

}

sum=sum+yearday;

if (year==1984)

{

sum-=1;

}

printf("距1984年1月1日一共有%d天\n",sum);

/*上面是计算输入的日期距1984年1月1日一共经历了多少天*/

weekday = (sum-1) % 7;

week = yearday / 7;

printf("今天是第%d个星期,星期%d",week,weekday);

return ;

}

下面是修改好的,能多给些分嘛?写程序不容易,还有,好好学习,这些不难,就是多花点时间而已

#include stdio.h

void main()

{

int year,month,day;

int tempmonth,yearday;

int week,weekday;

int sum=0;

int tag=0;

printf("输入年、月、日:\n");

scanf("%d %d %d",year,month,day);

tag =( year - 1988 )/4;

printf("tag=%d\n",tag);

sum=(year-1990)*365 + tag;

tempmonth = month - 1;

yearday = 0;

switch(tempmonth)

{

case 12:yearday+=31;

case 11:yearday+=30;

case 10:yearday+=31;

case 9:yearday+=30;

case 8:yearday+=31;

case 7:yearday+=31;

case 6:yearday+=30;

case 5:yearday+=31;

case 4:yearday+=30;

case 3:yearday+=31;

case 2:yearday+=28;

case 1:yearday+=31;

}

yearday = yearday+day;

if ((year-1988)%4==0 month 2)

{

yearday+=1;

}

sum=sum+yearday;

printf("sum=%d\n",sum);

printf("距1990年1月1日一共有%d天\n",sum);

/*上面是计算输入的日期距1990年1月1日一共经历了多少天*/

weekday = (sum-1) % 7+1;

week = yearday / 7;

printf("今天是第%d个星期,星期%d",week,weekday);

return ;

}

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语言程序,输入一个整数,输出星期几字符信息.如输入0,则输出"星期日"字符串.(不要写函数)

#includestdio.h

void main()

{

int a;

printf("input a num\n");

scanf("%d",a);

switch(a){

case 0:

printf("星期日\n");

break;

case 1:

printf("星期一\n");

break;

case 2:

printf("星期二\n");

break;

case 3:

printf("星期三\n");

break;

case 4:

printf("星期四\n");

break;

case 5:

printf("星期五\n");

break;

case 6:

printf("星期六\n");

break;

default:

printf("input fail\n");

break;

}

}


当前标题:c语言星期函数编程,c语言根据日期算星期几
URL地址:http://cdkjz.cn/article/dsigjcd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220