132. C Program to Convert Two dimensional array into one dimensional array.
How does this program work?
- In this programme you will learn about how to convert two dimensional array into one dimensional array matrix using C Language.
- variables are stored in two arrays.
- And then by using for loop converting into one dimensional array.
Here is the code
#include <stdio.h>
int main(void)
{
int arr[3][3]={{1,2,3},{4,5,6},{8,9,10}};
int arr2[9];
int i,j,k=0;
printf("2D-Array\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",arr[i][j]);//Display two dimensional array
arr2[k]=arr[i][j];
k++;
}
printf("\n");
}
printf("1D-Array\n");
for(i=0;i<9;i++)
printf("%d ",arr2[i]);//Display one dimensional array
return 0;
}