Manipulations with Arrays
ã¡ãã¥ãŒã衚瀺ããã«ã¯ã¹ã¯ã€ãããŠãã ãã
You can also use for loops in arrays to find the sum of all elements:
12345678int numbers[4] = {42, 12, 56, 98}; int sum = 0; for (int i = 0; i <= 3; i++) { sum += numbers[i]; } cout << sum;
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:
12345678int numbers[4]; int sum = 0; for (int i = 0; i <= 3; i++) { cout << "Type the number: "; cin >> numbers[i]; sum += numbers[i]; }
ã¹ã¯ã€ãããŠã³ãŒãã£ã³ã°ãéå§
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.
- Take input from the user.
- Multiply the user's number and the variable
mul. Store the result in the variablemul. - Print the variable
mul.
Please, donât forget to type the semicolon ; at the end of the lines.
è§£ç
ãã£ãŒãããã¯ããããšãããããŸãïŒ
single
AIã«è³ªåãã
AIã«è³ªåãã
äœã§ã質åããããææ¡ããã質åã®1ã€ã詊ããŠãã£ãããå§ããŠãã ãã