Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Manipulations with Arrays | Intro to Arrays
Introduction to C++
course content

Зміст курсу

Introduction to C++

Introduction to C++

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

bookManipulations with Arrays

You can also use for loops in arrays to find the sum of all elements:

12345678
int numbers[4] = {42, 12, 56, 98}; int sum = 0; for (int i = 0; i <= 3; i++) { sum += numbers[i]; } cout << sum;
copy

Here the variable sum will store the sum of all elements, initially, it’s equal to 0. Then we iterate through the array using for loops and add each element to the variable sum.

You can also store in arrays the data from the user:

12345678
int numbers[4]; int sum = 0; for (int i = 0; i <= 3; i++) { cout << "Type the number: "; cin >> numbers[i]; sum += numbers[i]; }
copy
Завдання
test

Swipe to show code editor

Find the multiplication of 10 elements printed by the user. Store the result in the variable mul. Pay attention that the initial value of the variable mul is 1, since multiplication by 1 does not affect the result.

  1. Take input from the user.
  2. Multiply the user's number and the variable mul. Store the result in the variable mul.
  3. Print the variable mul.

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

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookManipulations with Arrays

You can also use for loops in arrays to find the sum of all elements:

12345678
int numbers[4] = {42, 12, 56, 98}; int sum = 0; for (int i = 0; i <= 3; i++) { sum += numbers[i]; } cout << sum;
copy

Here the variable sum will store the sum of all elements, initially, it’s equal to 0. Then we iterate through the array using for loops and add each element to the variable sum.

You can also store in arrays the data from the user:

12345678
int numbers[4]; int sum = 0; for (int i = 0; i <= 3; i++) { cout << "Type the number: "; cin >> numbers[i]; sum += numbers[i]; }
copy
Завдання
test

Swipe to show code editor

Find the multiplication of 10 elements printed by the user. Store the result in the variable mul. Pay attention that the initial value of the variable mul is 1, since multiplication by 1 does not affect the result.

  1. Take input from the user.
  2. Multiply the user's number and the variable mul. Store the result in the variable mul.
  3. Print the variable mul.

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

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookManipulations with Arrays

You can also use for loops in arrays to find the sum of all elements:

12345678
int numbers[4] = {42, 12, 56, 98}; int sum = 0; for (int i = 0; i <= 3; i++) { sum += numbers[i]; } cout << sum;
copy

Here the variable sum will store the sum of all elements, initially, it’s equal to 0. Then we iterate through the array using for loops and add each element to the variable sum.

You can also store in arrays the data from the user:

12345678
int numbers[4]; int sum = 0; for (int i = 0; i <= 3; i++) { cout << "Type the number: "; cin >> numbers[i]; sum += numbers[i]; }
copy
Завдання
test

Swipe to show code editor

Find the multiplication of 10 elements printed by the user. Store the result in the variable mul. Pay attention that the initial value of the variable mul is 1, since multiplication by 1 does not affect the result.

  1. Take input from the user.
  2. Multiply the user's number and the variable mul. Store the result in the variable mul.
  3. Print the variable mul.

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

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

You can also use for loops in arrays to find the sum of all elements:

12345678
int numbers[4] = {42, 12, 56, 98}; int sum = 0; for (int i = 0; i <= 3; i++) { sum += numbers[i]; } cout << sum;
copy

Here the variable sum will store the sum of all elements, initially, it’s equal to 0. Then we iterate through the array using for loops and add each element to the variable sum.

You can also store in arrays the data from the user:

12345678
int numbers[4]; int sum = 0; for (int i = 0; i <= 3; i++) { cout << "Type the number: "; cin >> numbers[i]; sum += numbers[i]; }
copy
Завдання
test

Swipe to show code editor

Find the multiplication of 10 elements printed by the user. Store the result in the variable mul. Pay attention that the initial value of the variable mul is 1, since multiplication by 1 does not affect the result.

  1. Take input from the user.
  2. Multiply the user's number and the variable mul. Store the result in the variable mul.
  3. Print the variable mul.

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

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