![](/img/trans.png)
[英]I am trying to make a 5x5 tic tac toe program in C but facing some problem in looping I think. The program automatically displays player 1 as winner
[英]I'm trying to make a program which rotated the matrix clockwise, and I think there's some problem with pointers
#include <stdio.h>
#include <stdlib.h>
int main(){
int mat[3][3]={
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int nmat[3][3];
int *s=mat[0][0];
int *t=nmat[0][2];
int i;
for (i=0; i<3; i++){
*t=*s;
s++; t=t+3;
}
int *q=mat[2][0];
int *w=nmat[0][0];
for (i=0; i<3; i++){
*w=*q;
q++; w=w+3;
}
int *a=mat[2][0];
int *b=nmat[0][0];
for (i=0; i<3; i++){
*b=*a;
a=a-3; b++;
}
int *x=mat[2][2];
int *y=nmat[2][0];
for (i=0; i<3; i++){
*b=*a;
a=a-3; b++;
}
int *p=nmat[0][0];
int j;
for (i=0; i<3; i++){
for (j=0; j<3; j++){
printf("%d ", *p);
p++;
}
printf("\n");
}
}
我是 c 的初學者,我正在練習一些問題。 我正在嘗試制作一個順時針旋轉矩陣的程序,但它似乎不起作用。 我的代碼哪里錯了?
int *s=mat[0][0];
在這里,您將s
聲明為pointer of type int
的pointer of type int
,同時使用mat[0][0]
對其進行初始化,該類型為int
類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.