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.