啊哈磊_编程从这里起步

标题: 判断这个数是否是单数是输出yes不是输出no [打印本页]

作者: 行田然    时间: 2020-3-19 12:30
标题: 判断这个数是否是单数是输出yes不是输出no
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5.     int a;
  6.     scanf("%d",&a);
  7.     if (a==1,2,3,4,5,6,7,8,9)
  8. {
  9.     printf("yes");   
  10. }
  11.     else
  12. {
  13.     printf("no");
  14. }
  15.   return 0;
  16. }
复制代码

作者: The Death    时间: 2020-3-19 13:27
本帖最后由 The Death 于 2020-3-19 13:36 编辑

第7行那个逗号没用的,|| 才表示或还有,最好加一个while循环,可以重复用

作者: The Death    时间: 2020-3-19 13:34
本帖最后由 The Death 于 2020-3-19 14:11 编辑

修改后代码如下

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    while(1)
{
   scanf("%d",&a);
   if (a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==0)
   {
       printf("yes");
   }   
   else
   {   
        printf("no");
   }
}
   return 0;
}

作者: 嘟嘟编程    时间: 2020-3-21 14:01
本帖最后由 嘟嘟编程 于 2020-3-21 14:06 编辑

话不多说,上代码:
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n%2!=0)
        printf("Yes");
    else
        printf("No");
    return 0;
}




作者: 任涵予    时间: 2020-3-22 16:08
逗号是没用的,需要用逻辑或(||)





欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2