【发布时间】:2021-02-19 08:47:18
【问题描述】:
我是 C 编程新手,遇到一个简单的问题。下面是代码...
#include <stdio.h>
/* Write a C Program that accepts two integers from the
user and calculate the sum of the two intergers. Go to the editor!
*/
int main()
{
int firstInteger, secondInteger;
int sum;
printf("Input two Integers: \n");
scanf("%d%d", &firstInteger, &secondInteger);
sum = firstInteger + secondInteger;
printf("%d", sum);
return 0;
}
在 GCC 编译器上运行我的代码后,我没有得到我期望的结果!
C:\XXXX\XXXX\XXXX\XXXX\XXXX>gcc 2sumOfTwoIntegers.c
C:\XXXX\XXXX\XXXX\XXXX\XXXX>a
Input two Integers:
25, 38
25
为什么我没有得到我输入的整数的总和?
【问题讨论】:
-
这就是你检查
scanf()的返回值的原因! -
程序的赋值是接受来自用户的两个整数还是接受一个整数、一个逗号和一个整数?
标签: c scanf conversion-specifier