Learning C. Working with user-defind functions.
#include <stdio.h>
#include <stdlib.h>
int print_random_matrix (int m, int n);
void main (void)
{
int m, n;
printf("m: "); scanf("%d", &m);
printf("n: "); scanf("%d", &n);
print_random_matrix(m, n);
}
int print_random_matrix (int m, int n)
{
int i, j, a[20][20];
for (i= 1; i<= m; i++)
{
for (j= 1; j<= n; j++)
{
printf("%d ", rand()%10);
}
printf("\n");
}
//why does this work without RETURN?
}
As far as I know you need a return statement to return the value from the function you defined, but it works without one and I don't understand why. This code does not look right to me.
Is the code correct?
&
Why does it work right now?
&
How do I write the print_random_matrix function with a return statement?(if I have to)