我在本练习中的目标是创建一个函数名称MultiTwo(),该函数名称将用户插入的两个整数相乘,然后打印商。MultiTwo必须在里面调用main()。
这是我的尝试:
#include <stdio.h>
int MultiTwo(int x, int y, int result);
int main() {
int x, y, result;
printf("Insert an integer: \n");
x = scanf("%d", &x);
printf("Insert a second integer: \n");
y = scanf("%d", &y);
result = x * y;
printf("The quotient of the two inserted integers is: %d", result);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我插入两个整数,尽管插入了整数,但我总是得到的结果是 1。
x = scanf("%d", &x);
Run Code Online (Sandbox Code Playgroud)
这首先从输入中读取值并将其分配给变量 x。然后通过将 x 设置为 scanf() 的返回值来破坏该值,即成功读取的变量数,在本例中为 1。