My Subject Blog

C Program Swap Values

/* Write a program to swap (interchange) values of two variables with and without using third variable. */

#include <stdio.h>

int main(void) {
int a,b,c;
printf("Enter Value of a :");
scanf("%d",&a);
printf("Enter Value of b :");
scanf("%d",&b);
printf("\nBefore Swapping a = %d b = %d",a,b);
c=a;
a=b;
b=c;
printf("\nAfter Swapping (Using 3rd Variable) a = %d b = %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter Swapping (Without 3rd Variable) a = %d b = %d",a,b);
return 0;
}

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

C Program for Runtime Memory Allocation for Table of Integers

Followers