Programming Course in C# ¡Free!

Conditional and boolean

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Create a program that uses the conditional operator to give a boolean variable named "bothEven" the value "true" if two numbers entered by the user are the even, or "false" if any of them is odd.

Output



Solution


using System;
public class ConditionalB
{
public static void Main()
{
Console.Write("Enter number1: ");
int n1 = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter number2: ");
int n2 = Convert.ToInt32(Console.ReadLine());


bool both = ( (n1 % 2 == 0) && (n2 % 2 ==0) ) ? true : false;

Console.WriteLine( both ? "both" : "odd");
}
}