I've made a code which creates a matrix and sort it in ascending form. (row)
I want to do following things in the ex.'s that I've given with my code, but I can't find out how.
ex. If I enter "r" as the input; a matrix entered like this;
3 4 5
9 2 8
6 4 8
Should en up in that form;
3 4 5
2 8 9
4 6 8
and the output in the screen should be;
4
8
6
As we take the medians of the rows.
and, if I enter the input value as 'c' (which is for column sorting and median)
3 4 5
9 2 8
6 4 8
should re-order itself as;
3 2 5
6 4 8
9 4 8
and the median value should show up itself as;
6 4 8
Here is my full code;
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define n 3
int main()
{
int arr[n][n],min,i,j,tmp,y,k,w,z=0,q=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("Enter number: ");
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
z = j;
min = arr[i][j];
for (k = j +1 ; k < n; k++)
{
if (arr[i][k] < min)
{
min = arr[i][k];
z = k;
}
}
tmp=arr[i][j];
arr[i][j]=min;
arr[i][z]=tmp;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
getch();
}