Learn C Language from the Best Tutors
Search in
There are various ways using operators and expressions. The simplest way is always recommended with some physical world scenarios.
As you asked for algorithm only.
Declare and initialize two variables first, second
Step 1 → Add first and second and store to first
Step 2 → Subtract second from first and store to second
Step 3 → Subtract second from first and store to first
Swap completed.
Insight:
Assuming variable having value first=10 and second=20
Now adding first with second and storing the result 10+20=30 in first.
Now subtracting the second which is still 10 from first and storing the result 30-10=20 in second
Here we achieved the initial swap
Then subtracting second which is 20 from first 30-20=10 and storing the result in first complene the final swap as now value inside variable first is 10 and second is 20.
Thank you
read lessRelated Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Brilliant Academy, a reputed B. Tech Tuition...
Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...
Lasya Infotech: An educational Training...
Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
Looking for C Language Classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for C Language Classes are on UrbanPro
The best Tutors for C Language Classes are on UrbanPro