Home Computer Problems How To Write A Program to Swap two numbers in C Programming ?
Computer Problems
How To Write A Program to Swap two numbers in C Programming ?
Date: 14 Aug , 2015
Category: Computer Problems
View: 78493
Like
0 Like
Dislike
0 Des
Solutions















Swap two numbers with and without using third variable, swapping in c using pointers, functions (Call by reference) and using bitwise XOR operator, swapping means interchanging. For example if in your c program you have taken two variable a and b where a = 4 and b = 5, then before swapping a = 4, b = 5 after swapping a = 5, b = 4

In our c program to swap numbers we will use a temp variable to swap two numbers.

Programs.... Purpose of Hello world program may be to say hello to people or the users of your software or application.


Program Output.....



Swapping of two numbers without third variable....

You can also swap two numbers without using temp or temporary or third variable. In that case c program will be as shown.


To understand above logic simply choose a as 7 and b as 9 and then do what is written in program. You can choose any other combination of numbers as well. Sometimes it's a good way to understand a program.

Swap two numbers using pointers....




Swapping numbers using call by reference....

In this method we will make a function to swap numbers.


C programming code to swap using bitwise XOR....

In this method we will make a function to swap numbers.


Swapping is used in sorting algorithms that is when we wish to arrange numbers in a particular order either in ascending order or in descending.


By.
BebbiSingh


Comment :

Search tags : How To Write A Program to Swap two numbers in C Programming ? Computer Problems


ADVERTISMENT



Most Popular Solutions
Copyright © TheSolveProblems.Com 2015 - 2016 All Right Reserves | Powered by EarnEDU Pvt. Ltd. | Created by Bebbisingh
>>>>>>>>>>