using System; class Program { static void Main(string[] args) { int number = 7; if (number % 2 == 0) { Console.WriteLine(number + " is even."); } else { Console.WriteLine(number + " is odd."); } if (number < 0) { Console.WriteLine(number + " is negative."); } else if (number == 0) { Console.WriteLine(number + " is zero."); } else { Console.WriteLine(number + " is positive."); } bool isPrime = true; for (int i = 2; i <= number / 2; i++) { if (number % i == 0) { isPrime = false; break; } } if (isPrime) { Console.WriteLine(number + " is prime."); } else { Console.WriteLine(number + " is not prime."); } } }This example checks a condition (
number % 2 == 0
), branches based on the result using anif-else
statement, performs different actions based on the branch (Console.WriteLine()
), and repeats the process for two additional conditions (number < 0
andnumber % i == 0
). The following steps are performed:
- Define an
int
variablenumber
with the value 7.- Check if
number
is even using the conditionnumber % 2 == 0
.- If
number
is even, output a message to the console saying thatnumber
is even usingConsole.WriteLine()
.- If
number
is odd, output a message to the console saying thatnumber
is odd usingConsole.WriteLine()
.- Check if
number
is negative, zero, or positive using anif-else if-else
statement.- Output a message to the console saying whether
number
is negative, zero, or positive usingConsole.WriteLine()
.- Use a
for
loop to check ifnumber
is prime by iterating over all numbers between 2 andnumber / 2
.- If
number
is prime, output a message to the console saying thatnumber
is prime usingConsole.WriteLine()
.- If
number
is not prime, output a message to the console saying thatnumber
is not prime usingConsole.WriteLine()
.Note that there are many other types of conditional statements and logical operators you can use, such as
switch
,&&
,||
, and ternary operators (?:
). This example is just one possible multi-step process for working with conditional statements.