选择结构(多分支&综合)——吃瓜群众

任务描述
编写一个程序,判断给定重量的西瓜能否被切成两个偶数重量的部分。

输入输出要求
输入: 一个整数 weight,表示西瓜的重量,范围是 1 到 100。
输出: 如果西瓜可以被切成两个偶数重量的部分,输出 "YES, you can divide the watermelon into two even parts.";否则输出 "NO, you can't divide the watermelon into two even parts."

代码实现
cpp
#include <stdio.h>

int main() {
    int weight;
    scanf(&quot;%d&quot;, &amp;weight);
    if (weight > 2 &amp;&amp; weight % 2 == 0) {
        printf(&quot;YES, you can divide the watermelon into two even parts.\n&quot;);
    } else {
        printf(&quot;NO, you can't divide the watermelon into two even parts.\n&quot;);
    }
    return 0;
}

总结
通过这次练习,我加深了对条件判断和模运算符的理解。同时,我也意识到在编写代码时,清晰的逻辑和良好的代码风格是非常重要的。
全部评论

相关推荐

ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务