m0_74082038 2022-10-04 22:20 采纳率: 50%
浏览 326
已结题

大一的问题,希望可以得到答案的

大一新生,全英文教学,因为我们不允许用if语句,所以有些不知道如何做

img

img

img

img

img

img

  • 写回答

12条回答 默认 最新

  • _GX_ 2022-10-04 23:14
    关注

    1

    #include <stdio.h>
    
    int main()
    {
        int age;
        printf("Please enter your age: ");
        scanf("%d", &age);
        age < 18 ? printf("You are not eligible for voting as your age is %d\n", age)
                 : printf("You are eligible for vote as your age is %d, which is more than or equal to 18\n", age);
        return 0;
    }
    

    2

    #include <stdio.h>
    
    int main()
    {
        char c;
        printf("Please enter a character: ");
        scanf("%c", &c);
        int lowercase = c >= 'a' ? (c <= 'z' ? 1 : 0) : 0;
        int uppercase = c >= 'A' ? (c <= 'Z' ? 1 : 0) : 0;
        (lowercase || uppercase) ? printf("%c is an alphabet", c) : printf("%c is not an alphabet", c);
        return 0;
    }
    

    3

    #include <stdio.h>
    
    int main()
    {
        double temperature;
        printf("Please enter a temperature in centigrade: ");
        scanf("%lf", &temperature);
        printf("Temperature in Fahrenheit is: %.2lf\n", temperature * 9.0 / 5.0 + 32.0);
        temperature <= 15.0 ? printf("I am feeling cold\n")
                            : (temperature <= 25.0 ? printf("I am feeling okay, the temperature is fine\n")
                                                   : printf("I am feeling warm!\n"));
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 理科生的温柔 2022-10-04 22:56
    关注

    第一题是根据输入的年龄在18上下输出不同的提示,不用if的话就用三目运算符 ? :

    评论
  • IT技术分享社区 数据库领域优质创作者 2022-10-05 08:41
    关注

    选择判断语句,可以用switch 语句代替。switch适合条件比较固定的判断逻辑

    评论
  • 游坦之 全栈领域优质创作者 2022-10-05 13:19
    关注

    不能用if
    switch也可以吧

    评论
  • fuill 2022-10-06 00:20
    关注

    很多情况下if语句可以换成三目运算符

    评论
  • Code_流苏 C/C++领域优质创作者 2022-10-06 00:25
    关注

    方法一:三目运算符实现
    方法二:switch语句实现

    等都可以实现
    如有帮助,还请采纳!谢谢!

    评论
  • iecne 2022-10-06 08:16
    关注

    可以使用三目运算符解决,这样的方法更加快捷,而且无需用到if

    评论
  • 小黎的培培笔录 Java领域新星创作者 2022-10-06 09:42
    关注

    第一题用三目运算符
    第二题可以用equals来判断
    第三个用还是三目运算符简单

    评论
  • tnt1314 2022-10-06 13:03
    关注

    这不就是选择语句的练习题么,用switch或者case那些就好了

    评论
  • 悠灵本林 2022-10-06 17:53
    关注

    可以选择用三目运算符来解决 等价于 if

    评论
  • 门牙会稍息 2022-10-08 10:22
    关注

    用switch或三目来做

    评论
  • 快乐鹦鹉 2022-10-04 22:34
    关注

    你先翻译一下好吗
    不用if,就得用三目运算符了。你这是好几道题啊

    评论 编辑记录
查看更多回答(11条)

报告相同问题?

问题事件

  • 系统已结题 10月18日
  • 已采纳回答 10月10日
  • 修改了问题 10月4日
  • 修改了问题 10月4日
  • 展开全部

悬赏问题

  • ¥15 编译arm板子的gcc
  • ¥20 C语言用栈实现无向图邻接矩阵广度优先遍历
  • ¥15 C++代码报错问题,c++20协程
  • ¥15 c++图Djikstra算法求最短路径
  • ¥15 Linux操作系统中的,管道通信问题
  • ¥15 ansible tower 卡住
  • ¥15 等间距平面螺旋天线方程式
  • ¥15 通过链接访问,显示514或不是私密连接
  • ¥100 系统自动弹窗,键盘一接上就会
  • ¥50 股票交易系统设计(sql语言)