C/C++: 三元运算符“ ? : ”的用法

来源:互联网 发布:ubuntu下如何挂载u盘 编辑:程序博客网 时间:2024/05/16 19:21
#include <stdio.h>#include <stdlib.h>int main(void){    printf("请输入三个整数 eg: 1,2,3\n");    int x, y, z, nSum, nProduct, nMax, nMin;    double fAverage;    scanf("%d,%d,%d", &x, &y, &z);    nSum = x + y + z;    fAverage = nSum / 3.0;    nProduct = x*y*z;    nMax = x > y ? x : y;    nMax = nMax > z ? nMax : z;    nMin = x < y ? x : y;    nMin = nMin < z ? nMin : z;    printf("和为%d\n平均数为%lf\n积为%d\n最大数为%d\n最小数为%d\n", nSum, fAverage, nProduct, nMax, nMin);    system("pause");    return 0;}
0 0
原创粉丝点击