if (x > y) { z = x; } else { z = y; }

// 上机实验 #include <stdio.h>

int main() { int x = 123; int y = 45; int z; if (x > y) { z = x; } else { z = y; } printf('%d\n', z); // 输出123

int n = 789;
int digits = 0;
while (n > 0) {
    digits++;
    n /= 10;
}
printf('%d\n', digits); // 输出3

return 0;

}

C语言三元运算符与if语句等价实现及数字位数计算示例

原文地址: https://www.cveoy.top/t/topic/l0mS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录