我正在为学校开展一个项目。我们必须将两个数字分开并显示答案以及其余部分。函数中的值是正确的,但是当我试图通过main传递它时,它给出了错误的数字。谢谢你的帮助
#include <stdio.h>
void division (int number, int divisor, int *quotient, int *remainder);
int main(void)
{
int i, d, q, r;
int *quotient = &q;
int *remainder = &r;
printf("Enter an integer and divisor, separated by comma: ");
scanf("%d, %d", &i, &d);
division(i, d, quotient, remainder);
printf("%d divided by %d: quotient = %d, remainder = %d\n", i, d,
*quotient, *remainder);
return 0;
}
void division(int number, int divisor, int *quotient, int *remainder)
{
int a = number / divisor;
printf(" a = %d\n", a);
int b = number % divisor;
printf(" b = %d\n", b);
quotient = *a;
remainder = *b;
}
答案 0 :(得分:0)
您正在分割功能中正确分配值。 尝试 * quotient = a; * remainder = b; 您正在通过引用进行传递,因此您需要将值分配给商和余数。