Ejercicio
Condicional y booleano
Objetivo
Cree un programa en C# que utilice el operador condicional para dar a una variable booleana denominada "bothEven" el valor "true" si dos números introducidos por el usuario son pares, o "false" si alguno de ellos es impar.
Código de Ejemplo
using System; // Import the System namespace for basic functionality
class Program // Define the main class
{
static void Main() // The entry point of the program
{
// Ask the user to enter two numbers
Console.Write("Enter the first number: ");
int num1 = int.Parse(Console.ReadLine()); // Read and convert the first input to an integer
Console.Write("Enter the second number: ");
int num2 = int.Parse(Console.ReadLine()); // Read and convert the second input to an integer
// Use the conditional operator to check if both numbers are even
bool bothEven = (num1 % 2 == 0 && num2 % 2 == 0) ? true : false;
// Display the result
Console.WriteLine($"Both numbers are even: {bothEven}");
}
}