고수님들 댓글 마니부탁해요!!!
권뉴
질문 제목 : 4개의정수를쓰고 큰수2개더하고 작은수 2개더하는건데요질문 요약 :역기서 temp을 왜 지정해주는건지 이해가안되요 빠른답변부탁드릴게요 ㅜㅜ
temp = b; 왜하는건지 몰르겟어요 ㅜㅜ
b = a;
a = temp;
질문 내용 :
#include stdio.h
void main() {
int a=0, b=0, c=0, d=0;
int temp;
printf(Input #1: );
scanf(%d, &a);
printf(Input #2: );
scanf(%d, &b);
if(ba) {
temp = b;
b = a;
a = temp;
}
printf(Input #3: );
scanf(%d, &c);
if(ca) {
temp = c;
c = b;
b = a;
a = temp;
} else if(cb) {
temp = c;
c = b;
b = temp;
}
printf(Input #4: );
scanf(%d, &d);
if(da) {
temp = d;
d = c;
c = b;
b = a;
a = temp;
} else if(db) {
temp = d;
d = c;
c = b;
b = temp;
} else if(dc) {
temp = d;
d = c;
c = temp;
}
printf(Sum of Bigger 2: %d, smaller 2: %d\n, a+b, c+d);
}
}
-
스위트초코
temp 없이 a 와 b를 서로 바꿔 보세요.. ;;
그러면 temp 가 왜 있는지 알게될거예요 -
이루리
a와 b의 값을 서로 바꾸려고요.
a = b;
b = a;
하면 안바뀌어요. 생각해보세요.