thanks for the help, sorry for my bad english I'm trying to use a matrix with functions to input from user or fill the matrix with random numbers and then print it, but i can print only the last row, i think the problem is related with pointers, please help me The user choose if he wants to fill the matrix or use random numbers to do it, This is the code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 25
#define MIN 10
int i, j, y, x, n;
int mat [MAX] [MAX];
int main ()
{
int x, y, i, j, user, n;
printf ("Goodmorning, insert matrix dims (y,x): ");
scanf ("%d %d",&y,&x);
for (i=0;i<y;i++)
for (j=0;j<x;j++)
mat [i] [j] = 0;
printf ("\nInsert '0' for random, insert '1' for manual: ");
scanf ("%d", &user);
if (!user)
rand_matrix (mat [x], x, y);
if (user)
input_matrix (mat [x], x, y);
stampa_matrix (mat [x], x, y);
return 0;
}
rand_matrix (int matrix [y] [x] , int b, int a)
{
srand(time(NULL));
for (i=0;i<a;i++)
for (j=0;j<b;j++)
{
n = rand () % MAX + MIN;
matrix [i] [j] = n;
}
}
input_matrix (int matrix [y] [x], int b, int a)
{
for (i=0;i<a;i++)
for (j=0;j<b;j++)
scanf ("%d", &matrix[i] [j]);
}
stampa_matrix (int matrix [y] [x] , int b, int a)
{
for (i=0;i<a;i++)
{
printf ("\n");
for (j=0;j<b;j++)
printf ("%3d ", matrix [i] [j] );
}
}