| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Lesson 2-10: Swapping Variables

Page history last edited by Ms. R. Singh 11 years, 6 months ago

SWAPPING VARIABLES

 

When swapping the values stored in 2 variables, we would need to introduce a 3rd variablem called a 'temporary' variable, which will hold the value of one variable while the value from the other variable is transferred to the other one.

 

Eg.) Zack and Cody have the same last name.  In entering their marks, Cody’s mark was entered for Zack’s and vice versa.  Construct pseudocode algorithm and flowchart to interchange these two marks.

 

Answer

 

Start

     Input zack_mark, cody_mark

     temp_mark = zack_mark

     zack_mark = cody_mark

     cody_mark = temp_mark

     Print(‘Zack’s mark:  ‘,zack_mark)

     Print(‘Cody’s mark:  ‘,cody_mark)

Stop

 

 

Comments (0)

You don't have permission to comment on this page.