Advertisement
Advertisement
//C# - if else statement program
using System;
class A
{
public static void Main()
{
int a = 100, b = 50;
float f1 = 2.5f, f2 = 5.9f;
//If there is just one statement associated with an if-else block then
//no curly braces are needed
if(a>b)
Console.WriteLine("{0} is greater than {1}", a, b);
else
Console.WriteLine("{0} is less than {1}", a, b);
//If there is more than one statement associated with either of the if/else block in if-else then
//a pair of curly braces are needed
if(f1>f2)
Console.WriteLine("{0} is greater than {1}", f1, f2);
else
{
Console.WriteLine("{0} is less than {1}", f1, f2);
Console.WriteLine("Second statement to execute in else");
}
}
}
100 is greater than 50
2.5 is greater than 5.9
Second statement to execute in else
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement