English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
이하는 두 개의 변수를 교환하는 예제입니다.
#include <stdio.h> int main() { int a,b; printf("Enter the value of a : "); scanf("%d", &a); printf("\nEnter the value of b : "); scanf("%d", &b); a += b -= a = b - a; printf("\nAfter Swapping : %d\t%d", a, b); return 0; }
출력 결과
a의 값을 입력하세요 : 23 b의 값을 입력하세요 : 43 After Swapping : 4323
위 프로그램에서는 두 개의 변수 a와 b를 선언하고 실행 중에 동적으로 초기화했습니다.
int a,b; printf("Enter the value of a : "); scanf("%d", &a); printf("\nEnter the value of b : "); scanf("%d", &b);
세 번째 변수를 사용하지 않고 숫자를 교환합니다.
a += b -= a = b - a;