Find the best tutors and institutes for Tuition

Find Best Tuition

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Search for topics

Write a program to swap values of two variables with and without using third variable.

Asked by Last Modified  


Follow 15

228 Answers

Please enter your answer

With third variable Swap(a,b): c=a a=b b=c Without third variable Swap(a,b): a = a+b b= a-b a= a-b read more

With third variable






Without third variable


      a = a+b

      b= a-b

      a= a-b

read less

Programming is an creative Art . I help students to be creative artist by learning coding skill.

A=2 B=4 A=A+B B= A-B A=A-B

Student who can understand problems of other students better

Enter value of x,y than x = x+y than y = x-y than x = x-y print swapped value x,y.

Certified Tamil Teacher with 25 Years of Professional Teaching Experience

With 3rd Variable: int temp, a, b; temp = a; a = b; b = temp; Without 3rd Variable: int a,b; a = a + b; b = a - b; a = a - b;

Programming Language Instructor in C, C++, JAVA.

If you are coding in C++ language then this will help you: #include<iostream.h> int main(){ int a=10, b=20; a=a+b; b=a-b; a=a-b; cout<<a<<" "<<b; return 0; }


Hello sir, You can motivate the child by saying, " if you study, then I will give you chocolate (or whatever he likes)."


#include<stdio.h> int main() { int a=10, b=20; printf("Before swap a=%d b=%d",a,b); a=a+b;//a=30 (10+20) b=a-b;//b=10 (30-20) a=a-b;//a=20 (30-10) printf("\nAfter swap a=%d b=%d",a,b); return 0; }

Computer science teacher and Mathematics Teacher with 4 years of experience

enter value of x,y than x = x+y than y = x-y than x = x-y print swapped value x,y.

Professional Trainer with 6 years of experience Programming

#include<iostream>int main() { int a=10, b=20; a=a+b; b=a-b; a=a-b; cout<<"After swap a="<<a<<" b="<<b; return 0; } read more

int main()
    int a=10, b=20;
    cout<<"After swap a="<<a<<" b="<<b;
    return 0;

read less

Experienced IT Trainer, Academic Associate, IT Enthusiast

In Python, its dramatically easy, X = 15 Y = 10 X, Y = Y, X

View 226 more Answers

Related Lessons

Chapter 1: Introduction part 1
Hello, first chapter is an Introduction. So, Let's start with introducing our subject. Name of our subject is BASIC MECHNICAL ENGINEERING. so if we divide the name what we'll get..? First word is...

Nidhi R. | 3 days ago

0 0

How to greet people in German Language?
Let's see how do we greet/wish people in German Language. Guten Morgen = good morning Hallo= hello Guten Tag = good afternoon/good day Guten Abend = good evening Gute Nacht = good night Tschüss...

Prachi P. | 29 Apr

0 0

What is Strain Rate ?
Strain rate is how fast the strain is happening with respect to time dE/dt. In a quasi static test like a tensile test the strain rate is of the order of .001 per sec. For a slow phenomenon like creep...

Ashique Ellahi | 28 Apr

0 0

Recommended Articles

When it comes deciding the right school for children, parents definitely try to be accurate. Yet the competitive academic industry offers too many options when it comes to school for children and there begins the confusion. With new schools coming up, parents get utterly confused which school will be the best for their...

Read full article >

School, college, university or an open entrance exam, certain rules stands the same for any occasion. Doing mistake in these basic rules related to exams is foolish and simply impacts the examinee s performance. To help students score good and make any exam experience a memorable one, here is a list of six tips to follow....

Read full article >

Before sending children to school, parents hardly take the effort to well educate their children. Parents expect school to do everything and make the children become scholar. Though schools have significant roles to play in a child s life but certain developments and habits grow in a child, from parents end only. These...

Read full article >

Once over with the tenth board exams, a heavy percentage of students remain confused between the three academic streams they have to choose from - science, arts or commerce. Some are confident enough to take a call on this much in advance. But there is no worry if as a student you take time to make choice between - science,...

Read full article >

Looking for Tuition ?

Find best Tuition in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Looking for Tuition Classes?

Find best tutors for Tuition Classes by posting a requirement.

  • Post a learning requirement
  • Get customized responses
  • Compare and select the best

Looking for Tuition Classes?

Find best Tuition Classes in your locality on UrbanPro

Post your learning requirement is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on, to fulfill their learning requirements across 1,000+ categories. Using, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more