I created a 2d array where the user can write the size (column and row) and fill it with random numbers, but I am having trouble converting from 2d to 1d. My question is how can i convert 2d array to 1d(like i am creating 3x3 array like this 92 88 4 next line 6 10 36 next line 96 66 83 and i want to convert it like 92 88 4 6 10 36 96 66 83). And if there is a problem with my code, please tell me. (Sorry for my grammatical errors)
This is my code;
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Enter the number of rows: ");
int i;
scanf("%d", &i);
printf("Enter the number of columns: ");
int y;
scanf("%d", &y);
int array[i][y];
int rows, columns;
int random;
srand((unsigned)time(NULL));
for(rows=0;rows<i;rows++)
{
for(columns=0;columns<y;columns++)
{
random=rand()%100+1;
array[rows][columns] = random;
printf("%i\t",array[rows][columns]);
}
printf("\n");
}
return 0;
}