Turn Desktop View Off
You are here:   HomeC Programming (Pratical)C Program Calculate Basic Salary and Grow Salary of a Employee
by Dinesh Thakur Category: C Programming (Pratical)

In the program integer type variable declare(x,y) which contains the value. To swap the variables we need to declare them with unique values. To swap the variables without using third variable and in this case we also do not use the Temp (temporary) variable. Some operators for manipulation used for swapping the variable.

Problem Statement:
This Program is to swapping the two Variables without using Third variable.

  1. Entering the number.
  2. Using Logic to swap variables.
  3. Display the Output on the screen.

Syntax of Swapping:
x=x+y;
y=x-y;
x=x-y;

Here is source code of the C program Swap two variables without Using third variable. The C program is successfully compiled. The program output is also shown below.




#include<stdio.h>

void main()
{
    int x,y;
    clrscr();
    printf("\nPlease Enter a Number (x):");
    scanf("%d",&x);
    printf("\nPlease Enter a Number (y):");
    scanf("%d",&y);
    printf("\n\nValues Before Swapping\nx=[%d]\ny=[%d]",x,y);
    x=x+y;
    y=x-y;
    x=x-y;
    printf("\n\nValues After Swapping\nx=[%d]\ny=[%d]",x,y);
    getch();

Swap Two Number Without using Third Variable



Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us