2015. 4. 6. 15:16 Programing/Algorithm
3개의 숫자를 내림차순으로 정렬
#include <stdio.h>
void sort(int *x, int *y, int *z);
int main()
{
int x=4, y=11, z=8;
sort(&x, &y, &z);
printf("%d %d %d\n",x,y,z);
}
void sort(int *x, int *y, int *z){
int temp;
if(*x < *y){
temp = *x;
*x = *y;
*y = temp;
sort(x, y, z);
}
else if(*y < *z){
temp = *y;
*y = *z;
*z = temp;
sort(x, y, z);
}
else if(*x < *z){
temp = *x;
*x = *z;
*z = temp;
sort(x, y, z);
}
}
'Programing > Algorithm' 카테고리의 다른 글
Recursive Fibonacci (0) | 2015.04.06 |
---|---|
순환/재귀 팩토리알 구현 (0) | 2015.04.06 |
프로젝트 오일러 7번 (0) | 2015.02.10 |
프로젝트 오일러 6번 (0) | 2015.02.10 |
프로젝트 오일러 5번 (0) | 2015.02.10 |