Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, November 15, 2014

Program to swap two values without using third variable in C.

Swapping without third variable


Code Box
---------------------------------------------

/*program to swap two values without using third variable */

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();

printf("\nEnter two numbers :");
printf("\nEnter first number a= ");
scanf("%d",&a);

printf("\nEnter second number b= ");
scanf("%d",&b);

printf("\nValues before swapping a= %d & b= %d ",a,b);

a=a+b;   //swapping
b=a-b;
a=a-b;

printf("\nValues after swapping a= %d & b= %d ",a,b);

getch();
}

No comments: