菜鸟 求助!!

unkhown 2010-07-21 05:32:52
#include <stdio.h>

void transpose(int *a,int n);

int main(void)
{
int a[3][3] = {1,2,3,4,5,6,7,8,9};
int i,j;

transpose(a,3);

for(i = 0;i < 3;i++)
{
for(j = 0;j < 3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
system("pause");
return 0;

}

void transpose(int *a,int n)
{

int i,j,temp;
int (*p)[3];

p = a;
for(i = 0;i < n;i++)
for(j = i;j < n;j++)
{
if(i != j)
{
temp = *(*(p+i)+j);
*(*(p+i)+j) = *(*(p+j)+i);
*(*(p+j)+i) = temp;
}
}
}


矩阵转置 指针有问题

Dev C++下 9 [Warning] passing arg 1 of `transpose' from incompatible pointer type
28 [Warning] assignment from incompatible pointer type

谢谢谢谢
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fcly1981826ly 2010-07-21
  • 打赏
  • 举报
回复
学习学习学习学习学习
_JeffreyWu 2010-07-21
  • 打赏
  • 举报
回复


void transpose(int a[][3],int n);

int main(void)
{
int a[3][3] = {1,2,3,4,5,6,7,8,9};
int i,j;

transpose(a,3);

for(i = 0;i < 3;i++)
{
for(j = 0;j < 3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
system("pause");
return 0;

}

void transpose(int a[][3],int n)
{

int i,j,temp;
int (*p)[3];

p = a;
for(i = 0;i < n;i++)
for(j = i;j < n;j++)
{
if(i != j)
{
temp = *(*(p+i)+j);
*(*(p+i)+j) = *(*(p+j)+i);
*(*(p+j)+i) = temp;
}
}
}

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧