소 감 ¶
기존의 나열된 자료와는 다른 , 이차배열의 각각의 소트..
생각보다 어려웠다.
행과 열이 같이 for속에 들어가게 되면 값이 틀려져서 따로 처리하다보니 소스가 길어졌다.
더 좋은 방법이 있을까??
생각보다 어려웠다.
행과 열이 같이 for속에 들어가게 되면 값이 틀려져서 따로 처리하다보니 소스가 길어졌다.
더 좋은 방법이 있을까??
물론 이런 생각도 해 보았다. matrix를 temp1,2 matrix를 만들어서 행과 열을 따로 계산한다..
하지만 이번에 내 생각에 변수 낭비될 것 같고 해서 그냥 matrix 복사를 한번 더 했다.
하지만 이번에 내 생각에 변수 낭비될 것 같고 해서 그냥 matrix 복사를 한번 더 했다.
- 나름대로 sort에 대해 여러가지 생각을 하게 된 계기가 된 것 같다.
 연습장에 연필로 끄적끄적거려 보기도 하고.. 
 
 
또 더 좀더 효율적인 프로그램을 만들기 위해선 어떻게 해야할까 ? 그리고 C언어의 장점을 살리는 방법이 뭘까?
하고 생각해 봤다. 그래서 생각하면서 프로그래밍 한 것, 또 자초해서 해 버린 소트 때문에 시간이 많이 걸린 것 같다.
하고 생각해 봤다. 그래서 생각하면서 프로그래밍 한 것, 또 자초해서 해 버린 소트 때문에 시간이 많이 걸린 것 같다.
소 스 ¶
~cpp 
#include <stdio.h>
#define MATRIX_SIZE 4
void search_max(int matrix[][MATRIX_SIZE]);
void print_matrix(int matrix[][MATRIX_SIZE]);
void change(int *, int *);
int i, j;
void main()
{
	int matrix[MATRIX_SIZE][MATRIX_SIZE] = {{0,}};
	//3 * 3 입력 .
	for(i = 0; i < MATRIX_SIZE - 1; i++){
		for(j = 0; j < MATRIX_SIZE -1; j++){
			printf("matrix[%d][%d] = ", i, j);
			scanf("%d", &matrix[i][j]);
		}
	}
	// 가장 큰 수 찾기.
	search_max(matrix);
	//출력
	print_matrix(matrix);
}
void search_max(int matrix[][MATRIX_SIZE])
{
	int temp_matrix[4][4], a, b;
	for(i = 0; i < MATRIX_SIZE; i++){
		for(j = 0; j < MATRIX_SIZE; j++){
			temp_matrix[i][j] = matrix[i][j];
		}
	}
	//찾아 넣기 행
	for(i = 0; i < MATRIX_SIZE-1; i++){
		for(j = 0; j < MATRIX_SIZE-2; j++){
			if(temp_matrix[i][j] > temp_matrix[i][j+1]){
				change(&temp_matrix[i][j], &temp_matrix[i][j+1]);
			}
		}
		matrix[i][MATRIX_SIZE-1] = temp_matrix[i][MATRIX_SIZE-2];
	}
	for(i = 0; i < MATRIX_SIZE; i++){
		for(j = 0; j < MATRIX_SIZE; j++){
			temp_matrix[i][j] = matrix[i][j];
		}
	}
	//찾아 넣기 열
	for(i = 0; i < MATRIX_SIZE-1; i++){
		for(j = 0; j < MATRIX_SIZE-2; j++){
			if(temp_matrix[j][i] > temp_matrix[j+1][i]){
				change(&temp_matrix[j][i], &temp_matrix[j+1][i]);
			}
		}
		matrix[MATRIX_SIZE-1][i] = temp_matrix[MATRIX_SIZE-2][i];
	}
	//찾아 넣기 마지막
	for(i = 0; i < MATRIX_SIZE-2; i++){
		if(temp_matrix[MATRIX_SIZE-1][i] > temp_matrix[MATRIX_SIZE-1][i+1]){
				change(&temp_matrix[MATRIX_SIZE-1][i], &temp_matrix[MATRIX_SIZE-1][i+1]);
			}
		if(temp_matrix[i][MATRIX_SIZE-1] > temp_matrix[i+1][MATRIX_SIZE-1]){
				change(&temp_matrix[i][MATRIX_SIZE-1], &temp_matrix[i+1][MATRIX_SIZE-1]);
			}
	}
	a = temp_matrix[MATRIX_SIZE-1][MATRIX_SIZE-2];
	b = temp_matrix[MATRIX_SIZE-2][MATRIX_SIZE-1];
	matrix[MATRIX_SIZE-1][MATRIX_SIZE-1] =  a > b ? a : b;
}
void print_matrix(int matrix[][MATRIX_SIZE])
{
	for(i = 0; i < MATRIX_SIZE; i++){
		for(j = 0; j < MATRIX_SIZE; j++){
			printf("%5d", matrix[i][j]);
		}
		if(j == MATRIX_SIZE)
			printf("\n");
	}
}
void change(int *a, int *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}













