Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Desafio: Palavra-Chave Else | Estruturas de Controle
Fundamentos de C#

bookDesafio: Palavra-Chave Else

Write a condition to check if the number num is even or odd. If the number is even, output "Even", otherwise "Odd".

main.cs

main.cs

copy
12345678910111213141516
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int num = 5; // Write code below this line // Write code above this line } } }
  1. We can determine whether a number is even by verifying if its remainder, resulting from division by 2, equals zero.
  2. In code the condition will be x % 2 == 0 where x is the number to be checked.
main.cs

main.cs

copy
1234567891011121314151617181920212223
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int num = 5; // Write code below this line if (num % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); } // Write code above this line } } }

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 8

Pergunte à IA

expand

Pergunte à IA

ChatGPT

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

bookDesafio: Palavra-Chave Else

Deslize para mostrar o menu

Write a condition to check if the number num is even or odd. If the number is even, output "Even", otherwise "Odd".

main.cs

main.cs

copy
12345678910111213141516
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int num = 5; // Write code below this line // Write code above this line } } }
  1. We can determine whether a number is even by verifying if its remainder, resulting from division by 2, equals zero.
  2. In code the condition will be x % 2 == 0 where x is the number to be checked.
main.cs

main.cs

copy
1234567891011121314151617181920212223
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int num = 5; // Write code below this line if (num % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); } // Write code above this line } } }

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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