c program to swap two numbers without using third variable

>> Tuesday, November 1, 2011

This is another important program to swap two numbers without using third variable. The bold letters indicated in this program
describe the concept of how swapping is made withou using any other variable. Below is the program which is implementing swaping of two numbers.


#include<stdio.h> #include<conio.h> int main() { int a,b,temp; printf("enter two values\n"); printf("\na = "); scanf("%d",&a); printf("\tb = "); scanf("%d",&b); a=a+b; // swapping without using third variable b=a-b; a=a-b; printf("\na = %d\tb = %d ", a, b); getch(); }

Output :

C program to swap without using third variable

0 comments:

Post a Comment

About This Blog

This blog will contain c programs related to interview preparation, basic programs, operating system, graphics, data structure, algorithms implementation, compiler and porjects. C is one of the most widely used programming languages of all time. This blog is intended for engineer students and for the people who are preparing for their interview in IT sector.

Share and Save