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++ | Mobile-Friendly
course content

Conteúdo do Curso

Introduction to C++ | Mobile-Friendly

Introduction to C++ | Mobile-Friendly

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++) { &nbsp;&nbsp;&nbsp;&nbsp; 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:

What does the following code do? 

for (int i = 0; i <= 9; i++) {  mul *= numbers[i]; }

What does the following code do?

for (int i = 0; i <= 9; i++) { mul *= numbers[i]; }

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 3
some-alt