Search This Blog

C Program to Swap Two Numbers Without Third Variable

This post contains C program to swap two given numbers without using any temporary variable. Only the two variables are required, not a third.

C Program
#include<stdio.h>
void main()
{

int a,b;
printf("Enter first number, a:");
scanf("%d",&a);
printf("Enter second number, b:");
scanf("%d",&b);
printf("values of a and b before swapping is a=%d,b=%d",a,b);
/*swapping*/
a=a+b;
b=a-b;
a=a-b;
printf("value of a and b after swapping is a=%d,b=%d"a,b);
}


No comments: