c语言中条件运算符

 

001、c语言中条件运算符

复制代码
[root@localhost test]# cat test.c        ##  测试程序
#include <stdio.h>

int main(void)
{
        int n1, n2, max;

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

        max = (n1 > n2) ? n1:n2; //  条件运算符

        printf("max is %d\n", max);

        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 = 18
n2 = 34
max is 34
[root@localhost test]# ./kkk
please input two integers
n1 = 335
n2 = 54
max is 335
复制代码

 。

 

 。

 

posted @   小鲨鱼2018  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-09-03 c primer plus 9编程练习
点击右上角即可分享
微信分享提示