C语言 输出百分号(%)的方法

原文地址为: C语言 输出百分号(%)的方法

C语言中,如何输出百分号呢?

很简单,只要在格式控制符里输入2个 %% 就可以了,例如:

#include <stdio.h>
int main()
{
int a=90;
printf("%d%%\n",a);
return 0;
}

这样就会在屏幕上得到 90%

>> 现在有以下两对简单的代码:
>
> 1.
> #include<stdio.h>
> int main()
> {
> printf("%%");
> return 0;
> }
> 2.
> #include<stdio.h>
> int main()
> {
> printf("\%");
> return 0;
> }
>
> 在这一对代码中,1能够显示百分号,2不能


转义字符的问题吧?

现在再看下面这一对代码:
> 1.
> #include<stdio.h>
> int main()
> {
> printf("%%\n");
> return 0;
> }
> 2.
> #include<stdio.h>
> int main()
> {
> printf("\%\n");
> return 0;
> }
>
> 这个时候1和2都能显示百分号

转载请注明本文地址: C语言 输出百分号(%)的方法

猜你喜欢

转载自blog.csdn.net/wangchaoqi1985/article/details/81739272