001-004-013
Variable Swap and Update
Medium
Problem Description
Variable Swap and Update
In this problem: You will create a program that demonstrates three variable modification operations (increment, swap using a temporary variable, and compound assignment operators) and displays the results of each step to standard output.
Learning Objective: Understand variable value modification and the swap technique using a temporary variable
Overview
Perform the following three operations in order:
- Initialize
countto 5, increment by 1, and display - Initialize
ato 10 andbto 20, swap values using a temporary variable, and display - Initialize
scoreto 100, apply compound assignment operators (+=,-=,*=), and display each step
Specifications
- Step 1: Initialize
countto 5, increment withcount++, display result - Step 2: Set
a=10,b=20, swap using temp variable, display swapped values - Step 3: Set
score=100, applyscore += 50,score -= 30,score *= 2in order, display final value
Output Format
count: 6
a: 20, b: 10
score: 240
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up