C语言,,关于一个程序问题!~1

来源:百度知道 编辑:UC知道 时间:2024/06/19 20:51:49
#include <stdio.h>
struct solution {
float x1;
float x2;
};
cramer(float a[][],struct solution x);

main()
{float a[3][4];
struct solution x;
int i,j;
for (i=1;i<=2;i++)
{printf("\nPlease input the coefficents of equation %d.\n",i);
for (j=1;j<=3;j++)
scanf("%f",&a[i][j]);

}
cramer(a,x);
printf("x1=%g\n x2=%g",x.x1,x.x2);
getch();
}

cramer(float a[][],struct solution x)
{
float b;
b=a[1][1]*a[2][2]-a[2][1]*a[1][2];
x.x1=a[1][3]*a[2][2]-a[2][3]*a[1][2]/b;
x.x2=a[2][3]*a[1][1]-a[1][3]*a[2][1]/b;
return x;
}我不知道那错了,为什么错了,请高手帮帮忙!~!

帮你改了一下,你看看
#include <stdio.h>
struct solution {
float x1;
float x2;
};

void cramer(float a[][4],struct solution& x);

int main()
{float a[3][4];
struct solution x;
int i,j;
for (i=1;i<=2;i++)
{printf("\nPlease input the coefficents of equation %d.\n",i);
for (j=1;j<=3;j++)
scanf("%f",&a[i][j]);

}
cramer(a,x);
printf("x1=%g\n x2=%g",x.x1,x.x2);
scanf("%f",&a[0][0]);
}

void cramer(float a[][4],struct solution& x)
{
float b;
b=a[1][1]*a[2][2]-a[2][1]*a[1][2];
x.x1=a[1][3]*a[2][2]-a[2][3]*a[1][2]/b;
x.x2=a[2][3]*a[1][1]-a[1][3]*a[2][1]/b;
}