问下大佬这俩代码执行结果有啥不一样的,坐了一个算法题
#include<stdio.h>int main()
{
int weight;
scanf("%d",&weight);
if(weight==2||weight%4==0)
printf("YES, you can divide the watermelon into two even parts.");
else
printf("NO, you can't divide the watermelon into two even parts.");
}
#include<stdio.h>
int main()
{
int weight;
scanf("%d",&weight);
if(weight%2==0&&weight!=2)
printf("YES, you can divide the watermelon into two even parts.");
else
printf("NO, you can't divide the watermelon into two even parts.");
}
感觉这俩段差不多来着 if(weight==2||weight%4==0)
如果是 2 或 4的倍数 则打印 yes
if(weight%2==0&&weight!=2)
如果是 2 的倍数且不等于 2 则打印yes
能看出区别了么?
第一个取值范围: 2 4 8 12 16 20 ...
第二个取值范围: 4 6 8 10 12 14 ... yuxijian2020 发表于 2021-4-22 16:17
如果是 2 或 4的倍数 则打印 yes
如果是 2 的倍数且不等于 2 则打印yes
cao,谢谢大佬{:5_105:}
页:
[1]