【发布时间】:2019-05-08 16:34:39
【问题描述】:
在这段代码中,我以为我会得到 x / y 和 x - y 的计算结果,但程序显示 i 和 j 的值为 0。怎么了?
#include <stdio.h>
float calculate(float, float);
float i, j;
int main()
{
float a, b;
printf("Enter two numbers:\n");
scanf("%f%f", &a, &b);
printf("\nThe results are: %f %f %f\n", calculate(a, b), i, j);
return 0;
}
float calculate(float x, float y)
{
float r;
r = x * y;
i = x / y;
j = x - y;
return r;
}
【问题讨论】:
标签: c global-variables