【发布时间】:2022-11-18 21:18:55
【问题描述】:
这不是问题我只是想知道我是否可以使用更少的打印语句来解决这个问题。
#include <stdio.h> // for print statments
int main(int argc, char const *argv[]) {
int thisNumber;
printf("%s", "Hey you! input your Number here: " );
scanf("%d", &thisNumber );
printf( "%s","Your number is: " );
printf("%d\n", thisNumber );
return 0;
}
我试过这个:
#include <stdio.h> // for print statments
int main(int argc, char const *argv[]) {
int thisNumber;
printf("%s", "Hey you! input your Number here: " );
scanf("%d", &thisNumber );
printf( "Your number is: %d", thisNumber );
return 0;
}
输出是:
> Hey Bekhruz! input your Number here: <my input say:125>
> Your number is: 125%
出于某种原因,我在这段代码的末尾有一个 % 符号。为什么会发生,我该如何解决?谢谢!
【问题讨论】:
-
这并不能解释 % 符号,但你确实有
printf("%d\n", thisNumber );,它在末尾有换行符\n- 你没有在压缩版本中包含它 -
耶!它起作用了,实际上解决了我的 % 符号问题。谢谢你!