Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

2D ARRAY SORTING

Aim: To sort the given 2D Array Using C program Algorithm: Step 1: Start the Program. Step 2: Declare a 2D Array & Get Input from The User And Copy it to a another 1D Array. Step 3: Sort the Single Dimensional Array. Step 4: Print the Sorted Matrix Using Ordinary Matrix Printing. Step 5:Stop the Program. Program: #include<stdio.h> #include<conio.h> void main() { int a[100][100],i,j,t,x,y,k=0,c[100]; clrscr(); printf("Enter Rows & Coloumns..."); scanf("%d%d",&x,&y); printf("Enter A Mat Values..."); for(i=0;i<x;i++) { printf("\n"); for(j=0;j<y;j++) { scanf("%d",&a[i][j]); c[k]=a[i][j]; k++; } } for (i=0;i<(x*y-1);i++) { for(j=i+1;j<(x*y);j++) { if(c[i]>c[j]) { t=c[i]; c[i]=c[j]; c[j]=t; } }

2D ARRAY SORTING
} k=0; printf("Given Matrix \n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf(" %d ",a[i][j]); } printf("\n"); } printf("Sorted Matrix\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf(" %d ",c[k]); k++; } printf("\n"); } getch(); }

You might also like