Good morning everyone, I want in my code to leave the Main (); only with function call, all work is divided into small functions in the document.
I want to write an array [3] [3] in a function and organize and print it in other distinct functions. My code is to transpose an array, I believe my logic is correct, using bubble sort however the parameter pass is not working correctly since I am using pass-by-value and non-reference ...
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
void receberMatriz(int matriz[3][3])
{
int i, j;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
printf("Insira o valor de [%i][%i]: ", i, j);
scanf("%i", &matriz[i][j]);
}
}
}
void organizarMatriz(int matriz[3][3])
{
int i, j, aux;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
aux = matriz[i][j];
matriz[i][j] = matriz[j][i];
matriz[j][i] = aux;
}
}
}
void imprimirMatriz(int matriz[3][3])
{
int i, j;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
printf("[%i][%i]", i, j);
}
printf("\n");
}
}
int main(void)
{
int matriz[3][3];
receberMatriz(matriz);
imprimirMatriz(matriz);
//organizarMatriz(matriz); desabilitei chamada para testar valores recebidos e impressos pela matriz.
return 0;
}
How can I work with passing parameters from an array by reference? Or pointers ...?