gpt4 book ai didi

C编程代码错误

转载 作者:行者123 更新时间:2023-11-30 21:25:20 25 4
gpt4 key购买 nike

所以程序仍然不完整,我不能再继续了,因为第一次输入后就出现错误,我尝试使用 Visual Studio 2010 和 2015,都有同样的问题:

unhandled exception at 0x60eae42e (msvcr100d.dll) in asd.exe: 0xc0000005: Access violation writing location 0xccccccccc

谁能找出其中的问题吗?或者测试一下它是否可以在您的电脑上运行?这段代码应该是c

int main()
{
int y[3][3], inv[3][3], co[3][3], d[3], sol[3], D = 0,i=0, j = 0;
char z;
start: // Used to restart the program when the persons want to do more work or has done an error
printf("The format for the linear equation is\na1.X + b1.Y + c1.Z = d1\na2.X + b2.Y + c2.Z = d2\na3.X + b3.Y + c3.Z = d3\n");
for (i = 0;i < 3;i++)
{
for (z = 'a';z < 'd';z++,j++)
{
printf("Enter the value for %c%i\n", z, i + 1);
scanf("%i", y[i][j]);
}
printf("Enter the valie for D%i\n", i + 1);
scanf("%i", d[i]);
j = 0;
}
for (i = 0;i < 3;i++)
for (j = 0;j < 3;j++)
co[i][j] = (y[(i + 1) % 3][(j + 1) % 3] * y[(i + 2) % 3][(j + 2) % 3]) - (y[(i + 1) % 3][(j + 2) % 3] * y[(i + 2) % 3][(j + 1) % 3]);
for (i = 0;i < 3;i++)
D += y[i][0] * co[i][0];
if (D == 0)
{
printf("\nThese equations cannot be solved!\n");
}
for (i = 0;i < 3;i++)
for (j = 0;j < 3;j++);
for (i = 0;i < 3;i++)
for (j = 0;j < 3;j++)
inv[i][j] = co[i][j] / D;
for (i = 0;i < 3;i++)
{
sol[i] = 0;
for (j = 0;j < 3;j++)
sol[i] += inv[i][j] * d[j];
}
printf("The solutions are\nX=%i\nY=%i\nZ=%i\n", sol[0], sol[1], sol[2]);
getch();
goto start;


}

最佳答案

这些:

scanf("%i", y[i][j]);
scanf("%i", d[i]);

需要:

scanf("%i", &y[i][j]);
scanf("%i", &d[i]);

as %iscanf 中需要一个 int*(变量的地址),而不是 int >(变量值)。

<小时/>

另一个问题是你在这里除以零:

inv[i][j] = co[i][j] / D;

D为零时。

关于C编程代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com