如何在C编程中不使用第三个或临时变量交换两个数字?

如何在C编程中不使用第三个或临时变量交换两个数字?

通过加法和减法操作,我们可以将两个数字从一个内存位置交换到另一个内存位置。

算法

以下是算法的解释 −

开始

Step 1: Declare 2 variables x and y. Step 2: Read two numbers from keyboard. Step 3: Swap numbers. //Apply addition and subtraction operations to swap the numbers. i. x=x+y ii. y=x-y iii. x=x-y Step 4: Print x and y values.登录后复制