c语言中条件运算符 + 语句

 

001、

复制代码
[root@localhost test]# ls
test.c
[root@localhost test]# cat test.c
#include <stdio.h>

int main(void)

{
        int n1,n2;

        puts("please input two integers.");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);

        (n1 == n2) ? puts("equal"):puts("no equal");    //条件运算符后直接加执行语句

        return 0;
}
[root@localhost test]# gcc test.c -o kkk
[root@localhost test]# ls
kkk  test.c
[root@localhost test]# ./kkk
please input two integers.
n1 = 8
n2 = 3
no equal
[root@localhost test]# ./kkk
please input two integers.
n1 = 7
n2 = 7
equal
复制代码

 。

 

posted @   小鲨鱼2018  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-09-04 什么是Phasing?
点击右上角即可分享
微信分享提示