1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdio.h> //전처리기 #define SIZE 3 typedef struct{ //구조체 char name[10]; double w; }WEIGHT; void swap(WEIGHT *, WEIGHT *); //함수선언 int main(void) { WEIGHT man[SIZE]={{"홍길동",54.5}, {"김삿갓",125.6}, {"심봉사",35.7} }; int i,j; //변수 선언 for(i=0;i<2;i++){ //제어문 for(j=i+1;j<3;j++){ if(man[i].w<man[j].w){ swap(&man[i],&man[j]); } //call by reference } } printf("\n 이름 \t체중"); for(i=0;i<3;i++){ printf("\n %s %5.1f",man[i].name,man[i].w); } return 0; } //main()함수 끝 /* --------swap함수 정의------------------*/ void swap(WEIGHT *mani, WEIGHT *manj) { //함수 정의 WEIGHT temp; temp=*mani; *mani=*manj; *manj=temp; } | cs |
'Programming > C언어' 카테고리의 다른 글
[C언어] C언어의 역사와 특징 (0) | 2016.12.05 |
---|---|
[C언어] 구구단 출력하기 (0) | 2016.08.03 |
[C언어] 무한 반복하는 사칙연산 계산기 (2) | 2016.08.02 |
[C언어] 성적처리 프로그램 1.6 (2016.07.24 업데이트) (0) | 2016.07.24 |
[C언어] 성적처리 프로그램 1.5 (1) | 2016.07.22 |