ZKX's LAB

【C语言】程序功能:按示例格式完成以下要求。假设某年某月有31天,从键盘输入该月1日的星期数 编程从键盘输出某年某月

2021-04-26知识2

C语言编程:输入某年某月某日,判断这一天是这一年的第几天?语言编程,不知道是否可以用数组,但是觉得太复杂?怎么用数组解答?用switch我会,判断这一天是这一年的第几天:。

关于C语言简易编程 计算某年某月多少天 |#includevoid main(){int year,month;printf(\"\\n Please input year:\\n\");scanf(\"%d\",&year);printf(\"enter month:\\n\");scanf(\"%d\",&month);if(year%4=0){if(month=2)printf(\"\\n day=d\",29);else{if(month=4|month=6|month=9|month=11)printf(\"\\n day=d\",30);elseprintf(\"\\n day=d\",31);}}else{if(month=2)printf(\"\\n day=d\",28);else{if(month=4|month=6|month=9|month=11)printf(\"\\n day=d\",30);elseprintf(\"\\n day=d\",31);}}}只是把输入部分改了 输出结果是对的 还有你的32313133353236313431303231363533e58685e5aeb931333330356263判断闰年的方法有误应该是if(i%4=0&i%100。0|i%400=0)则i为闰年

在C语言中 使用switch语句编写“显示某年某月的天数”程序: 我们可以这样写12345678910111213141516171819202122232425switch(month){ case 2:{ if((year%2=0&year%100。0)|year%400=0)/这是闰年的判断条件,一下就知道了 { day=29;} else { day=28;} break;} case 4:case 6:case 9:case 11:day=30;break;这一部分是小月,利用了switch的特性,没有break就继续执行 case 1:case 3:case 5:case 7:case 8:case 10:case 12:day=31;break;这一部分是大月,跟上面小月一样}

#编程从键盘输出某年某月

随机阅读

qrcode
访问手机版