Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

- Clipping Path | Photoshop Masking |... by Sadi Chowdhury 4242 views
- Raster Scan And Random Scan by Devika Rangnekar 65199 views
- 6 Key Principles Of Making A Web De... by Clippingimages 4405 views
- Case study by Devika Rangnekar 1897 views
- Raster Scan and Raster Scan Displays by Saravana Priya 14718 views
- Clipping Path | Image Masking | Pho... by Clippingimages 6273 views

1,206 views

Published on

Problem Solving Techniques

No Downloads

Total views

1,206

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

43

Comments

7

Likes

1

No notes for slide

- 1. ALGORITHM FOR EXCHANGING TWO VALUES
- 2. EXCHANGING THE VALUES OF TWO VARIABLES Problem statement To exchange the values of the variables assigned to them. Algorithm development The problem of interchanging the data associated with two variables involves a very fundamental mechanism that occurs in many sorting and data manipulation algorithm. Ex: a b 4 5 Here a has 4 and b has 5. our aim is to replace the variable of a with 4 and b with 5.
- 3. So the target solution may look as a 5 b 4 Here we can make use of the assignment operator a = b; b = a; where the b value is assigned to a. the value has been changed, and the changed a value has been assigned to b. a = 5, b=5
- 4. So we make use of the temporary variable. t = a; a = b; b = t; Now, t = 4, a = 5, b = 4 Our target solution has been achieved.
- 5. Algorithm Description: 1. Save the original value of a in t. 2. Assign to a the original value of b. 3. Assign to b the original value of a that is stored in t.
- 6. Program Implementation # include <iostream.h> #include <conio.h> main () { int a = 4, b = 5, t; cout<<“The original value of a=“<<a<<“b=“<<b; t = a; a = b; b = t; cout<<“After exchanging a=“<<a<<“b=“<<b; }
- 7. APPLICATION This kind of swapping technique is applicable for all kinds of sorting algorithm.

No public clipboards found for this slide

Login to see the comments