Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Desafio: Laços em Arrays | Arrays
Fundamentos de C#

bookDesafio: Laços em Arrays

Loop through the numbers array and if the value of the element is even, add 1 to it, and if it's odd, multiply it by two. The original array should be modified.

main.cs

main.cs

copy
123456789101112131415161718192021222324252627
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for(_____) { if(_____) { _____ } else { _____ } } foreach(int i in numbers) { Console.WriteLine(i); } } } }
  1. All the numbers that give a remainder 0 when divided by 2 are called even numbers.
  2. Use the loop variable i to index and access the array elements.
main.cs

main.cs

copy
1234567891011121314151617181920212223242526272829
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for(int i = 0; i < numbers.Length; i++) { if(numbers[i] % 2 == 0) { numbers[i] += 1; } else { numbers[i] *= 2; } } foreach(int i in numbers) { Console.WriteLine(i); } } } }

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 8

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you show me an example of the `numbers` array?

What programming language should I use for this task?

Can you explain how to use a loop to modify the array in place?

bookDesafio: Laços em Arrays

Deslize para mostrar o menu

Loop through the numbers array and if the value of the element is even, add 1 to it, and if it's odd, multiply it by two. The original array should be modified.

main.cs

main.cs

copy
123456789101112131415161718192021222324252627
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for(_____) { if(_____) { _____ } else { _____ } } foreach(int i in numbers) { Console.WriteLine(i); } } } }
  1. All the numbers that give a remainder 0 when divided by 2 are called even numbers.
  2. Use the loop variable i to index and access the array elements.
main.cs

main.cs

copy
1234567891011121314151617181920212223242526272829
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for(int i = 0; i < numbers.Length; i++) { if(numbers[i] % 2 == 0) { numbers[i] += 1; } else { numbers[i] *= 2; } } foreach(int i in numbers) { Console.WriteLine(i); } } } }

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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