Translate

Labels

Friday, 14 June 2013

PROGRAM TO CONVERT 2-D ARRAY TO 1-D ARRAY

#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\n ");
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\n");
for(i=0;i<MAXROW;i++)
{
for(j=0;j<maxcol;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Equivalent one dimensional array\n");
for(i=0;i<MAXROW*MAXCOL;i++)
printf("%d\t",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 

No comments: