如何在C中使用`printf()`打印百分比字符

When writing a C program you might have the need to print the % percentage character using printf().

编写C程序时,可能需要使用printf()打印%百分比字符。

Perhaps you are working on a program that calculates percentages, which is kind of common when you’re just learning the language and you’re creating small programs.

也许您正在开发一个计算百分比的程序,这在您只是学习语言并创建小型程序时很常见。

How do you do so?

你如何做?

If you try to use it like this:

如果您尝试像这样使用它:

printf("%");

it will not work, and the compiler will give you a warning like

它不起作用,编译器会给您类似的警告

hello.c:9:14: warning: incomplete format specifier
      [-Wformat]
  printf("%");
          ^
1 warning generated.

and it is not printed.

并且不打印。

To make it work, you need to write %%, like this:

要使其正常工作,您需要像这样写%%

printf("%%");

翻译自: https://flaviocopes.com/c-print-percentage/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值