C Program For sorting of elements row wise in a matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],t,i,j,p,q,k;
clrscr();
printf("enter order of matrix a");
scanf("%d%d",&p,&q);
printf("\n enter %d values",p*q);
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&a[i][j]);
}
printf("\n elements of matrix a are:");
for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("%d\t",a[i][j]);
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
for(k=j+1;k<q;k++)
{
if(a[i][j]>a[i][k])
{
t=a[i][j];
a[i][j]=a[i][k];
a[i][k]=t;
}
}
}
}
printf("\n after sorting");
for(i=0;i<p;i++)
{
printf("\n"); printf("%d\t",a[i][j]);
}
getch();
} for(j=0;j<q;j++)



Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment