以下程序的输出是什么?这里%dn在printf中的作用是什么。 [英] What is the output of following Program ? Here what is the role of %dn inside printf .
本文介绍了以下程序的输出是什么?这里%dn在printf中的作用是什么。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
void main()
{
int a = 100;
int b = 3;
int c;
c = a + b;
printf( "a + b = %dn", c );
c = a - b;
printf( "a - b = %dn", c );
/* multiplication performed before call to printf() */
printf( "a * b = %dn", a * b );
c = a / b;
printf( "a / b = %dn", c );
c = 100 % 3;
printf( "a % b = %dn", c );
}
推荐答案
%d表示输出为 d igit(有符号十进制整数) ): http://www.cplusplus.com/reference/cstdio/printf/ [ ^ ]
你在 \ n,试试这个:
%d means that the output is a digit (Signed decimal integer): http://www.cplusplus.com/reference/cstdio/printf/[^]
You are missing backslash in "\n", try this:
#include <stdio.h>
void main()
{
int a = 100;
int b = 3;
int c;
c = a + b;
printf( "a + b = %d\n", c );
c = a - b;
printf( "a - b = %d\n", c );
/* multiplication performed before call to printf() */
printf( "a * b = %d\n", a * b );
c = a / b;
printf( "a / b = %d\n", c );
c = 100 % 3;
printf( "a % b = %d\n", c );
}
Umm,%d
用于格式化字符串。但是这里n
和%d一起使用,这意味着缺少了一些东西,即\
或n
本身如果你想在变量值后打印n
。
简而言之,它表示一个十进制数后跟一个字符n
。
-KR
Umm,%d
is used to format the string. But heren
is used along with the %d, which means there's something missing i.e.\
orn
itself if you want to printn
after the variable value.
So in short, it signifies a decimal number followed by a charactern
.
-KR
运行它并查看。
但我怀疑n部分应该是\ n换一个换行。
为什么要求我们为你运行一个程序?这很简单:将其粘贴到IDE中,构建应用程序并运行它!
Run it and see.
But I suspect that the "n" part should be "\n" for a new line instead.
Why ask us to run a program for you? This is trivial: paste it into your IDE, build the app, and run it!
这篇关于以下程序的输出是什么?这里%dn在printf中的作用是什么。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文