Imam ovaj kod i treba da matricu transponujem u funkciji.
Riješio sam to ovako, ali mi se čini da postoji ljepše rješenje.
Da ne bih puno pričao evo kod:
#include <stdio.h>
#define MAX 10
void citaj (int* p, int n);
void pisi (int* p, int n);
void transp (int* p, int n);
int main()
{
int n;
int mat[MAX][MAX];
printf ("Unesite red matrice: "); scanf("%d",&n);
printf("%d",sizeof(mat[0]));
citaj (mat[0],n);
pisi (mat[0],n);
transp (mat[0],n);
pisi (mat[0],n);
getch ();
}
/*
funkcije citaj, pisi i transp
odradjuju posao...
*/
void citaj(int* p, int n)
{
int i, j, *ptr;
printf ("\nUnesite elemente matrice po vrstama: \n");
ptr = (int *)p;
for (i=0;i<=n-1;i++) {
for (j=0;j<=n-1;j++){
printf("mat[%d][%d]: ",i,j);
scanf("%d", ptr++);
}
for (j=0;j<=MAX-n-1;j++,ptr++) *ptr = 0;
}
for (i=0;i<=MAX-n-1;i++,ptr++) *ptr = 0;
}
/*
pisi
*/
void pisi(int *p, int n)
{
int i, j, *ptr;
printf ("\nElementi matrice: \n");
ptr = (int *)p;
for (i=0;i<=n-1;i++) {
for (j=0;j<=n-1;j++) printf("%3d",*(ptr++));
printf("\n");
for (j=0;j<=MAX-n-1;j++,ptr++);
}
for (i=0;i<=MAX-n-1;i++,ptr++);
}
/*
transp
*/
void transp(int *p, int n)
{
int i, j, *ptr, tmp1, tmp[MAX][MAX];
printf ("\nTransponujem matricu...");
ptr = (int *)p;
for (i=0;i<=MAX-1;i++)
for (j=0;j<=MAX-1;j++)
tmp[i][j] = *(ptr++);
ptr = (int *)p;
for (i=0;i<=MAX-1;i++)
for (j=0;j<=MAX-1;j++) {
*ptr = tmp[j][i];
ptr++;
}
printf ("\t\t[ OK ]\n");
}