Saturday, January 4, 2014

C# if - else statement

// Try this code

int num;
Console.WriteLine("Enter a number");
num = int.Parse(Control.ReadLine());
if(num % 2 == 0)
{
   Console.WriteLine("The number is even");
}
else
{
   Console.WriteLine("The number is odd");
}

// Test multiple conditions using the if-else statement

if(condition!)
{
   statements if the condition 1 is true;
}
else if (condition 2)
{
   statements if the condition 2 is true;
}
else
{
   statement if none of the condition are true;
}

No comments:

Post a Comment