C programming code error -
so program still incomplete, cant go further cause there error right after first input, tried using visual studio 2010 , 2015, both same problem:
unhandled exception @ 0x60eae42e (msvcr100d.dll) in asd.exe: 0xc0000005: access violation writing location 0xccccccccc
so can find problem in this? or test , see if working on pc? code supposed 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 restart program when persons want more work or has done error printf("the format 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"); (i = 0;i < 3;i++) { (z = 'a';z < 'd';z++,j++) { printf("enter value %c%i\n", z, + 1); scanf("%i", y[i][j]); } printf("enter valie d%i\n", + 1); scanf("%i", d[i]); j = 0; } (i = 0;i < 3;i++) (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]); (i = 0;i < 3;i++) d += y[i][0] * co[i][0]; if (d == 0) { printf("\nthese equations cannot solved!\n"); } (i = 0;i < 3;i++) (j = 0;j < 3;j++); (i = 0;i < 3;i++) (j = 0;j < 3;j++) inv[i][j] = co[i][j] / d; (i = 0;i < 3;i++) { sol[i] = 0; (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; }
these:
scanf("%i", y[i][j]); scanf("%i", d[i]);
needs be:
scanf("%i", &y[i][j]); scanf("%i", &d[i]);
as %i
in scanf
expects int*
(address of variable), not int
(value of variable).
another problem division 0 here:
inv[i][j] = co[i][j] / d;
when d
zero.
Comments
Post a Comment