0
我開始編寫代碼,現在我一直在撓頭。我怎樣才能將一個變量分配給一個數組的位置?將一個變量賦值給一個數組[C]
我希望用戶插入A,B,C和D,然後將值存儲爲向量,以便稍後可以使用行斜率進行操作。
int a, b, c, d, e, f, g, h;
int AB, CD, AC, BD;
printf("\n\n A ___________________ B");
printf("\n | | ");
printf("\n | | ");
printf("\n | | ");
printf("\n | | ");
printf("\n |___________________| ");
printf("\n C D ");
printf("\n\n\nA(a, b):");
printf("\n-> ");
scanf("%d", &a);
printf("\n-> ");
scanf("%d", &b);
printf("\n\nB(c, d): ");
printf("\n-> ");
scanf("%d", &c);
printf("\n-> ");
scanf("%d", &d);
printf("\n\nC(e, f): ");
printf("\n-> ");
scanf("%d", &e);
printf("\n-> ");
scanf("%d", &f);
printf("\n\nD(g, h): ");
printf("\n-> ");
scanf("%d", &g);
printf("\n-> ");
scanf("%d", &h);
printf("\n\nA = (%d, %d)", a, b);
printf("\n\nB = (%d, %d)", c, d);
printf("\n\nC = (%d, %d)", e, f);
printf("\n\nD = (%d, %d)", g, h);
//VECTOR AB
AB[0]=c-a;
AB[1]=d-b;
//VECTOR CD
CD[0]=g-e;
CD[1]=h-f;
//VECTOR AC
AC[0]=e-a;
AC[1]=f-b;
//VECTOR BD
BD[0]=g-c;
BD[1]=h-d;
該代碼的最後一部分不起作用,所以我假設我不能像這樣分配變量。我能做些什麼來完成這項工作?
非常感謝!