

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include int main() { int a, b, temp; printf("Enter two numbers: "); scanf("%d %d", &a, &b); printf("Before exchange: a = %d, b = %d\n", a, b); temp = a; a = b; b = temp; printf("After exchange: a = %d, b = %d\n", a, b); return 0; }
Enter two numbers: 10 20 Before exchange: a = 10, b = 20 After exchange: a = 20, b = 10
Program 2: Exchange Two Variables Without a Temporary Variable
#include int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); printf("Before exchange: a = %d, b = %d\n", a, b); a = a + b; b = a - b; a = a - b; printf("After exchange: a = %d, b = %d\n", a, b); return 0; }
Enter two numbers: 10 20 Before exchange: a = 10, b = 20 After exchange: a = 20, b = 10