PROGRAM TO CONVERT 2 D ARRAY TO 1 D ARRAY

Sunday, April 13, 2014

#define MAXROW 3
#define MAXCOL 2
main()
{
int a[MAXROW][MAXCOL],B[MAXROW*MAXCOL];
INT I,J,K=0;
printf("Enter the matrix elements in row order
");

for(i=0;i<MAXROW;i++);
for(j=0;j<MAXCOL;j++);
{
scanf("%d",&a[i][j]);
b[k++]=a[i][j];
}

printf("Given two dimensional array
");

for(i=0;i<MAXROW;i++)
{
for(j=0;j<maxcol;j++)
printf("%d ",a[i][j]);
printf("
");

}
printf("Equivalent one dimensional array
");

for(i=0;i<MAXROW*MAXCOL;i++)
printf("%d ",b[i]);
}


OUTPUT:

Enter the matrix elements in row order
10   15   20   25   30   35
Given two-dimensional array
10     15
20     25
30     35
Equivalent one-dimensional array
10     15     20     25     30     35 

Related Posts by Categories

0 comments:

Post a Comment

Copyright © 2014 Information Sharing | Powered By Blogger