Random binary matrix

Need to make a random size (x = rows, y = columns) matrix which is filled with random numbers (only 0 or 1). So, if I don't know the size of the matrix, I use dynamic array. So far I have made this far, but obviously it isn't quite correct... Now I can get only one dimension array with random natural numbers.

Is it even possible to make this matrix (random rows, random collumns, filled with random numbers)? If so, than I would appreciate any help with the code.. Or the size of the matrix must to be initiated before filling it?

If you want random numbers for each x and y you would need to separate their random number generation. Otherwise you would be randomizing the same value for both the row value and column value. Unless that is what you want!

For initializing each element in the 2d array I've always used nested for loops such as..

First off you want to call srand() before you use rand() otherwise you will always get the same value for the first random.

Also you can take a look at a snippet I made for allocating memory in a 2 dimensional array. It uses user input and it expands on every input but you only need it once. here.

Or you can just random the 2 numbers (x, y) and after that random you can declare the multidimensional array and then make your for() loop and fill it with random 1s and 0s.

Your random is assigning x and y both the same value (1 or 0). This could result in the array being [0][0]. For making random number you can use this formula num = (rand() % max+1-min) + min; for the size of your array. Then use rand() % 2; for your assignment for each value.

If this doesn't help just ask and I'll write you a quick example for what you need.

Need to make a random size (x = rows, y = columns) matrix which is filled with random numbers (only 0 or 1). So, if I don't know the size of the matrix, I use dynamic array. So far I have made this far, but obviously it isn't quite correct... Now I can get only one dimension array with random natural numbers.

Is it even possible to make this matrix (random rows, random collumns, filled with random numbers)? If so, than I would appreciate any help with the code.. Or the size of the matrix must to be initiated before filling it?

P.S. First time with random number generation for me

Lines 14 and 16 - get rid of the semicolons. With the semicolons there, there is no loop.

Line 15 - it would be an error with the semicolons above, but after you take them out, notice that you don't use your loop control variable i in this line. You need to use it as an array index.

Line 18 - Once you actually declare the array and fill it in correctlyu, **A is going to point to A[0][0]. Again, you don't use your loop control variable j as an array index and you need to.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...