【问题标题】:I am not getting the output i desire我没有得到我想要的输出
【发布时间】:2020-09-17 18:05:57
【问题描述】:
#include <stdio.h>
int main() {
    int a, b;
    printf("Enter a number: ");
    scanf("%d", &a);
    printf("Enter another number: ");
    scanf("%d", &b);
    int add = a+b;
    printf("a + b = %d", add);
    return 0;
}

上面是 C 代码,它使用运算符。

我使用 TDM-GCC 4.9.2 64 位 编译器。

每当我运行上述程序时,我都会得到以下输出:

Enter a number:
4

--------------------------------
Process exited after 16.11 seconds with return value 3221225477
Press any key to continue . . .

不允许我输入任何其他号码,也不允许显示任何提示

我想要这个输出:

Enter a number:
4
Enter another number:
2
a + b = 6

--------------------------------
Process exited after <seconds> seconds with return value 0
Press any key to continue . . .

是编译器的问题还是代码的错误?

【问题讨论】:

  • 对问题的解释是否正确?还是我应该添加更多信息?
  • 尝试使用-Wall -Wextra 构建;对于scanf() 需要传递对变量ab 的引用
  • 什么是-Wall -Wextra 以及如何使用它构建?
  • 我整理了所有的错误并编辑了部分代码。它现在运行良好!

标签: c io operators


【解决方案1】:
#include <stdio.h>
int main()
{
    int a, b;

    printf("Enter a number: ");
    scanf("%d", &a);
    printf("Enter another number: ");
    scanf("%d", &b);
    int add = a+b;
    printf("a + b = %d \n", add);
    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多