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 @ 2024-09-03 12:59  小鲨鱼2018  阅读(6)  评论(0编辑  收藏  举报