分享兴趣,传播快乐。
增长见闻,留下美好!
亲爱的您,这里是LearningYard新学苑。
今天小编为大家带来的是
C语言(十四):习题练习-三天打鱼两天晒网。
Sharing interests。
Spread happiness。
Growth insights。
Leave behind the beauty!
Dear you,this is LearningYard New School.
What the editor brings to you today is
C language (14):
Exercise Exercise - Three days of fishing and two days of net drying.
一、思维导图
此推文关于习题练习-三天打鱼两天晒网的内容主要如下:
The main content of this tweet about exercise exercises - three days of fishing and two days of online exposure is as follows:
二、解题思路
1、判断输入数据是否合理。比如说年份、月份,月份对应的日期。当年份不合理直接跳出,年份合理时,三天打鱼两天晒网上一句,通过使用switch语句进行判断,将大月、小月,2月分组判断,再判断对应组下的天数。
2、当前面输入的数据都合理时,判断之后每一年是平年还是闰年。运用for循环和if语句,平年一年365天,闰年一年366天。再判断经历月份天数,使用switch语句,注意平年与闰年2月天数不同。
3、最后计算总天数,5天为一个周期。当余数为4或0时晒网,其它打渔。
1. Determine whether the input data is reasonable. For example,year,month,and the corresponding date of the month. If the current year is not reasonable,jump out directly. If the year is reasonable,use the switch statement to judge by grouping big months,small months,and February,and then determine the number of days under the corresponding group.
2. When the data entered earlier is reasonable,determine whether each subsequent year is a regular year or a leap year. Using the for loop and if statement,there are 365 days in a normal year and 366 days in a leap year. To determine the number of months and days experienced,use the switch statement and note that the number of days in February is different between regular and leap years.
3. Finally,calculate the total number of days,with 5 days as a cycle. When the remainder is 4 or 0,dry the net while fishing for others.
三、代码分析
1、输入数据
1. Input data
2、判断数据是否正确
”三天打鱼“的下一句是两天晒网。1、三天打鱼,两天晒网【sān tiān dǎ yú,liǎng tiān shài wǎng】:比喻对学习、工作没有恒心,经常中断,不能长期坚持。2、出自:清·曹雪芹《红楼梦》第九回:“因此也假说。
2. Determine if the data is correct
3、当输入正确数据时,判断后面每一年天数并累加
4、判断每个月的天数
4. Determine the number of days per month
三天打鱼两天晒网——不务正业。三天打鱼两天晒网既可以作为歇后语前半部分,也可以作为成语或俗语单独使用。释义: 原意是一共五天,三天用来打鱼,两天用来晒网,这是打鱼的最佳方式,后来用作比喻对学习或者工作没有恒心,经。
四、解题代码
int main()
{
int y,m,d;
int sum = 0;
scanf(&34;,&y,&m,&d);
if (y < 1990)//输入的年份不合理
{
printf(&34;);
return 0;
}
{
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (d > 31 || d < 1)
{
printf(&34;);
return 0;
}
break;//闰年时,输入的大月天数不合理
case 2:
if (d > 29 || d < 1)
{
printf(&34;);
return 0;
}
break;//闰年时,输入二月天数不合理
case 4:
三天打鱼的后一句是两天晒网。三天出海打渔,回来用两天时间修补晾晒渔网,这是打渔的最佳方式。每天打渔每天晒网的方式是不可能的。出海打渔期间是不可能修补渔网的。“三天打鱼,两天晒网”是俗语,不是成语。“三天打鱼。
case 6:
case 9:
case 11:
if (d > 30 || d < 1)
{
printf(&34;);
“三天打鱼,两天晒网”,这句话并不是歇后语,属于成语,没有下一句。三天打鱼,两天晒网,拼音:sān tiān dǎ yú,liǎng tiān shài wǎng。释义:比喻对学习、工作没有恒心,经常中断,不能长期坚持。语法:复句。
return 0;
}
break;//闰年时输入的小月天数不合理
default:
printf(&34;);
return 0;
break;//输入的其他数据,不符合要求
}
}
else
{
switch (m)
{
case 1:
case 3:
case 5:
“三天打鱼”的下一句是“两天晒网”,比喻对学习、工作没有恒心,经常中断,不能长期坚持,出自曹雪芹《红楼梦》:因此也假说来上学,不过是三日打鱼,两日晒网,白送些束修礼物与贾代儒。例句:1、如果没有计划,学习。
case 7:
case 8:
case 10:
case 12:
if (d > 31 || d < 1)
{
printf(&34;);
return 0;//平年时,输入的大月天数不合理
}
break;
case 2:
if (d > 28 || d < 1)
{
printf(&34;);
return 0;//平年时,输入的二月天数不合理
}
break;
case 4:
case 6:
case 9:
case 11:
if (d > 30 || d < 1)
{
printf(&34;);
return 0;//平年时,输入的小月天数不合理
}
break;
default:
printf(&34;);
return 0;
break;
}
}
int i;
if (y > 1990)
{
for (i = 1990; i < y; i++)
{
if ((i % 100 != 0 && i % 4 == 0) || (i % 400 == 0))
{
sum = sum + 366;
}
else
{
sum = sum + 365;
}
}
}
int i1;
if (m > 1)
{
for (i1 = 1; i1 < m; i1++)
{
if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0))
{
switch (i1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sum = sum + 31;
break;
case 2:
sum = sum + 29;
break;
case 4:
case 6:
case 9:
case 11:
sum = sum + 30;
break;
}
}
else
{
switch (i1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sum = sum + 31;
break;
case 2:
sum = sum + 28;
break;
case 4:
case 6:
case 9:
case 11:
sum = sum + 30;
break;
}
}
}
}
sum = sum + d;
sum = sum % 5;
if (sum == 0 || sum == 4)
{
printf(&34;);
三天打鱼两天晒网 既可以作为歇后语前半部分,也可以作为成语或俗语单独使用,拼音如下:释义: 原意是一共五天,三天用来打鱼,两天用来晒网,这是打鱼的最佳方式,后来用作比喻对学习或者工作没有恒心,经常中断,不能长期坚持。
}
else
{
printf(&34;);
}
return 0;
}
结语:C语言的学习需要配合不断地练习,对于推文有什么需要改进的地方,代码错误的地方还请大家提出来。
今天的分享就到这里了。
欢迎给我们留言。
让我们相约明天。
祝您今天过得开心快乐!
That&39;s sharing.
please leave us a message.
Let's meet tomorrow.
I wish you a happy day!
翻译:百度翻译
文案&排版:易春秀
审核:闫庆红