我想打电话给printf
,所以它会打印 1 donut
如果donuts
变量(类型为int
)的值是1
,则变量n widgets
的值是n
,其中widget
是printf
的值。
如何在不使用任何 if
语句或任何其他语句的情况下,对printf
进行单个函数调用;该代码必须是对Major Major Category Total
Petroleum Eng Engineering 1001
Nuclear Eng Engineering 4350
Marketing Business 10035
Accounting Business 3051
的单个调用?
答案 0 :(得分:2)
printf(" %d %s\n", donuts == 1 ? donuts : widgets, donuts == 1 ? "donuts" : "widgets");
http://www.tutorialspoint.com/ansi_c/ternary_operator_examples.htm