whats the problem with my codes. i want to sort it by column, thanks :)
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,c,temp;
int a[3][3],b[3][3];
temp=0;
printf("Please enter the array:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Array entered is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
} printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;++j){
if(a[i][j]<a[i][j+1])
{
temp=a[i][j];
a[i][j]=a[i][j+1];
a[i][j+1]=temp;
}
if(a[i][j]>a[i][j+2])
{
temp=a[i][j+2];
a[i][j]=a[i][j+2];
a[i][j]=temp;
}
}
}
printf("the sorted array is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
getch();
return 0;
}
Last edited on