Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Simple Math | Variables
Introduction to C++
course content

Зміст курсу

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

Simple Math

To perform arithmetic operations on variables and values C++ supports the following arithmetic operators:

Let’s try:

12345
int sum = 10 + 3; // 13 int dif = 10 - 3; // 7 int mul = 10 * 3; // 30 int div = 10 / 3; // 3 int mod = 10 % 3; // 1
copy

By division, any remainder was dropped since we assign the result to the int variable which doesn’t contain any decimals.

You can use all operations above to perform calculations on values, variables, or between variable and value:

123
double a = 32 + 13; // 45 double b = a + 25; // 45 + 25 = 70 double c = a + b; // 70 + 45 = 115
copy

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 5
toggle bottom row

Simple Math

To perform arithmetic operations on variables and values C++ supports the following arithmetic operators:

Let’s try:

12345
int sum = 10 + 3; // 13 int dif = 10 - 3; // 7 int mul = 10 * 3; // 30 int div = 10 / 3; // 3 int mod = 10 % 3; // 1
copy

By division, any remainder was dropped since we assign the result to the int variable which doesn’t contain any decimals.

You can use all operations above to perform calculations on values, variables, or between variable and value:

123
double a = 32 + 13; // 45 double b = a + 25; // 45 + 25 = 70 double c = a + b; // 70 + 45 = 115
copy

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 5
toggle bottom row

Simple Math

To perform arithmetic operations on variables and values C++ supports the following arithmetic operators:

Let’s try:

12345
int sum = 10 + 3; // 13 int dif = 10 - 3; // 7 int mul = 10 * 3; // 30 int div = 10 / 3; // 3 int mod = 10 % 3; // 1
copy

By division, any remainder was dropped since we assign the result to the int variable which doesn’t contain any decimals.

You can use all operations above to perform calculations on values, variables, or between variable and value:

123
double a = 32 + 13; // 45 double b = a + 25; // 45 + 25 = 70 double c = a + b; // 70 + 45 = 115
copy

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

To perform arithmetic operations on variables and values C++ supports the following arithmetic operators:

Let’s try:

12345
int sum = 10 + 3; // 13 int dif = 10 - 3; // 7 int mul = 10 * 3; // 30 int div = 10 / 3; // 3 int mod = 10 % 3; // 1
copy

By division, any remainder was dropped since we assign the result to the int variable which doesn’t contain any decimals.

You can use all operations above to perform calculations on values, variables, or between variable and value:

123
double a = 32 + 13; // 45 double b = a + 25; // 45 + 25 = 70 double c = a + b; // 70 + 45 = 115
copy

Завдання

Robin has 18$ and Ted has 12$. How much money has each of them in average?

  1. Calculate the sum of their money and assign it to the variable sum.
  2. Divide the sum by 2 (number of people) to find the average and assign the result to the variable avr.
  3. Print the variable avr.

Please, don’t forget about semicolon ; at the end of lines.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 5
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt