Skip to content

Addition and Subtraction

Addition

  • Addition combines two or more numbers to find their total sum.
c
int a = 5, b = 3, result;
result = a + b;
c++
int a = 5, b = 3, result;
result = a + b;
java
int a = 5, b = 3, result;
result = a + b;
python
a, b = 5, 3
result = a + b

Subtraction

  • Subtraction finds the difference between two numbers.
c
int a = 5, b = 3, result;
result = a - b;
c++
int a = 5, b = 3, result;
result = a - b;
java
int a = 5, b = 3, result;
result = a - b;
python
a, b = 5, 3
result = a - b

Example

Emma planning her monthly expenses. She started with a budget of $2000 for the month. Throughout the month, she made purchases and received her paycheck. She bought a laptop for $800, went out for dinner costing $50, and received her paycheck of $1500. She also paid her monthly rent of $700.

Pseudocode

txt
BEGIN
    INITIALIZE budget = 2000
    SUBTRACT budget = budget - 800
    SUBTRACT budget = budget - 50
    ADD budget = budget + 1500
    SUBTRACT budget = budget - 700
    OUTPUT "Final budget is: ", budget
END
c
int budget = 2000;
budget -= 800;

budget -= 50;
budget += 1500;

budget -= 700;

printf("Final budget is: $%d\n", budget);

return 0;
c++
int budget = 2000;
budget -= 800;

budget -= 50;
budget += 1500;

budget -= 700;

cout << "Final budget is: $" << budget << endl;
return 0;
java
int budget = 2000;
budget -= 800;

budget -= 50;
budget += 1500;

budget -= 700;

System.out.println("Final budget is: $" + budget);
python
budget = 2000
budget -= 800

budget -= 50
budget += 1500

budget -= 700

print("Final budget is: $" + str(budget))