c - 为什么我的程序结合了两个 printf 命令?

标签 c eclipse printf

这是我的程序。它应该写出一些整数的平方。

#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/

相关文章:

复制用户的输入并将其显示在屏幕上

c - 在 C 中打印前导 0

使用 pthreads 计算列表中的数字..C

arrays - 将字符串 char 设置为 null 会导致 C 中的内存泄漏吗?

c++ - ncurses、menu.h 和 current_item() 的问题

java - 在服务启动时更改图像

java - 重复的局部变量

c - C 和 SICP 中的尾递归

eclipse - Spring Tool Suite 创建新的spring starter 项目报错

c - printf中的*有什么用?