I want to write a function in C that takes a integer n as an argument and generates n^2 random numbers ( 1 < n <10). I want to store these n^2 numbers in a float *arr. arr is later on passed to another function that rearranges the array into a n*n matrix.
For Examples the first n elements in the first row, next n in the second row and so on. How can I generate the random numbers so that all rows in the end matrix are not the same.
When n was small like 3 I was creating the array manually like
float* arr;
arr = malloc(9*sizeof(float));
float temp[9] = {1,1,1,1,1,1,1,1,1};
arr = temp;
I want to test it for bigger values of n. So how do I do it?
Aucun commentaire:
Enregistrer un commentaire