0
0
C Sharp (C#)programming~10 mins

If-else execution flow in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

C Sharp (C#)
int number = 5;
if (number [1] 0)
{
    Console.WriteLine("Positive number");
}
Drag options to blanks, or click blank then click option'
A<
B>
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks only if the number is zero.
2fill in blank
medium

Complete the code to print "Even" if the number is even.

C Sharp (C#)
int num = 4;
if (num % 2 [1] 0)
{
    Console.WriteLine("Even");
}
Drag options to blanks, or click blank then click option'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check for odd numbers instead.
Using '>' or '<' does not make sense for checking remainder.
3fill in blank
hard

Fix the error in the if-else statement to correctly print "Negative" or "Non-negative".

C Sharp (C#)
int val = -3;
if (val [1] 0)
{
    Console.WriteLine("Negative");
}
else
{
    Console.WriteLine("Non-negative");
}
Drag options to blanks, or click blank then click option'
A<=
B>=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will check for positive numbers instead.
Using '>=' or '<=' includes zero, which is not negative.
4fill in blank
hard

Fill both blanks to print "Adult" if age is 18 or more, otherwise "Minor".

C Sharp (C#)
int age = 20;
if (age [1] 18)
{
    Console.WriteLine("Adult");
}
else
{
    Console.WriteLine("[2]");
}
Drag options to blanks, or click blank then click option'
A>=
B<
CMinor
DAdult
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>=' reverses the logic.
Printing "Adult" in the else block is incorrect.
5fill in blank
hard

Fill all three blanks to print "Fizz", "Buzz", or "FizzBuzz" based on divisibility.

C Sharp (C#)
int number = 15;
if (number [1] 3 == 0 && number [2] 5 == 0)
{
    Console.WriteLine("[3]");
}
Drag options to blanks, or click blank then click option'
A%
CFizzBuzz
DFizz
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' causes wrong checks.
Printing "Fizz" instead of "FizzBuzz" when divisible by both.