In: Computer Science
C Programming Only
Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array.
Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
#include <stdio.h>
#include <stdlib.h>
// Driver program
int main(void)
{
int arr[24];
int arr1[6][4];
for(int i = 0; i<24; i++)
arr[i]=rand()%1000;
for(int i = 0; i<24; i++)
printf("%d ",arr[i]);
printf("\n\n\n");
int index=0;
for(int i=0;i<6;i++)
for(int j=0;j<4;j++)
arr1[i][j]=arr[index++];
for(int i=0;i<6;i++){
for(int j=0;j<4;j++)
printf("%5d ",arr1[i][j]);
printf("\n");
}
return 0;
}