From a824561fca0548ab9846a274593ab8b740f480b0 Mon Sep 17 00:00:00 2001 From: Sreehari0101 <109453037+Sreehari0101@users.noreply.github.com> Date: Sat, 29 Oct 2022 09:29:41 +0530 Subject: [PATCH] Swap without an extra variable --- EfficientSwap.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 EfficientSwap.c diff --git a/EfficientSwap.c b/EfficientSwap.c new file mode 100644 index 0000000..4b86eb1 --- /dev/null +++ b/EfficientSwap.c @@ -0,0 +1,15 @@ +#include + int main() +{ + int a,b; + printf("Enter first number: "); + scanf("%d",&a); + printf("Enter second number: "); + scanf("%d",&b); +printf("Before swap a=%d b=%d",a,b); +a=a+b; +b=a-b; +a=a-b; +printf("\nAfter swap a=%d b=%d",a,b); +return 0; +}