003-004-013

Basic Compound Assignment Operators

Easy

Problem Description

Basic Compound Assignment Operators

In this problem: You will create a program using compound assignment operators (+=, -=, *=, /=, %=) to update a variable's value and print each result.

Learning Objective: Understand compound assignment operator behavior and their equivalence to regular assignment

Overview

Compound assignment operators use the form "variable operator= value" to perform an operation and assignment in one statement. x += 5 is equivalent to x = x + 5. They are very commonly used in practice because they make code more concise.

Specifications

  • Declare an int variable with initial value 100
  • Add 30 with +=, subtract 20 with -=, multiply by 2 with *=, divide by 4 with /=, get remainder with 3 using %=
  • Print the value after each operation

Output Format

Start: 100
After += 30: 130
After -= 20: 110
After *= 2: 220
After /= 4: 55
After %= 3: 1

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