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:

  1. Initialize count to 5, increment by 1, and display
  2. Initialize a to 10 and b to 20, swap values using a temporary variable, and display
  3. Initialize score to 100, apply compound assignment operators (+=, -=, *=), and display each step

Specifications

  • Step 1: Initialize count to 5, increment with count++, display result
  • Step 2: Set a=10, b=20, swap using temp variable, display swapped values
  • Step 3: Set score=100, apply score += 50, score -= 30, score *= 2 in 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