Day 3: Intro to Conditional Statements Solution in C# & Python | 30 Days of Code
4 min readDec 24, 2022
Screenshot for those who want to take a look at the question:
Solution in C#
To solve the “Day 3: Intro to Conditional Statements” problem on HackerRank using C#, you need to write a program that reads an integer n
from the console and performs the following actions:
- If
n
is odd, print "Weird" to the console. - If
n
is even and in the inclusive range of 2 to 5, print "Not Weird" to the console. - If
n
is even and in the inclusive range of 6 to 20, print "Weird" to the console. - If
n
is even and greater than 20, print "Not Weird" to the console.
Here is an example solution in C#:
using System;
namespace ConditionalStatements
{
class Program
{
static void Main(string[] args)
{
// Read input
int n = int.Parse(Console.ReadLine());
// Check if n is odd
if (n % 2 == 1)
{
Console.WriteLine("Weird");
}
// Check if n is even and in the range of 2…