2015-06-20 145 views
-4

所以該程序還沒有完成,我不能去任何進一步的原因還有一個錯誤的第一輸入以後,我嘗試使用Visual Studio 2010和2015年,兩個同樣的問題:C編程代碼錯誤

0000005:在asd.exe 0x60eae42e(msvcr100d.dll)

未處理的異常訪問衝突寫入位置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; 


} 
+1

for(i = 0; i <3; i ++)for(j = 0; j <3; j ++);'0.0.0 –

+1

'start://用於在人們想要做的時候重啓程序更多的工作或做了錯誤'使用循環而不是使用'goto'。 –

回答

1

這些:

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

需要是:

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

%iscanf期望一個int*(可變的地址),而不是一個int(變量的值)。


的另一個問題是,你通過零這裏做除法:

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

D爲零。