这是我的程序。它应该写出一些整数的平方。
#include <stdio.h>
int main (){
int a;
printf("Type an intiger.");
scanf("%i", &a);
printf("Square of that intiger is %i", a*a);
return 0;
}
当我在 Eclipse 中运行程序时,它首先要求我输入一个数字。我输入了 5。然后它给出了我的输出
Type an intiger.Square of that intiger is 25.
它应该首先打印“Type an intiger”,然后是其余的。但它只是结合了两个 printf 命令。问题是什么?
最佳答案
您需要一个newline character - printf("输入一个整数。\n");
In computing, a newline, also known as a line break or end-of-line (EOL) marker, or simply break, is a special character or sequence of characters signifying the end of a line of text.
整数的格式说明符是%d
scanf("%d", &a);
printf("Square of that intiger is %d", a*a);
关于c - 为什么我的程序结合了两个 printf 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20189557/