Search This Blog

30 May, 2011

Swapping two numbers without using third variables - C program


/* Swapping two numbers (using two variables) - SWAPTWO.C */

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first no. ");
scanf("%d",&a);
printf("Enter the second no. ");
scanf("%d",&b);
printf("/n Before Swapping: \n");
printf("a= %d \t b= %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n After Swapping: \n");
printf("a=%d \t b=%d",a,b);
getch();
}

No comments:

Post a Comment

Meetme@