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

Nested conditional execution 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 = 10;
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 number equals zero, not positive.
2fill in blank
medium

Complete the code to check if a number is positive and even.

C Sharp (C#)
int number = 8;
if (number > 0 && number [1] 2 == 0)
{
    Console.WriteLine("Positive even number");
}
Drag options to blanks, or click blank then click option'
A+
B/
C*
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' checks division but not remainder.
Using '*' or '+' does not check evenness.
3fill in blank
hard

Fix the error in the nested if statement to check if a number is positive and less than 100.

C Sharp (C#)
int number = 50;
if (number > 0)
{
    if (number [1] 100)
    {
        Console.WriteLine("Number is positive and less than 100");
    }
}
Drag options to blanks, or click blank then click option'
A!=
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks if number is greater than 100, which is incorrect here.
Using '==' or '!=' checks equality, not range.
4fill in blank
hard

Fill both blanks to create a nested if that checks if a number is positive and divisible by 5.

C Sharp (C#)
int number = 25;
if (number [1] 0)
{
    if (number [2] 5 == 0)
    {
        Console.WriteLine("Positive and divisible by 5");
    }
}
Drag options to blanks, or click blank then click option'
A>
B<
C%
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positivity.
Using '/' instead of '%' for divisibility check.
5fill in blank
hard

Fill all three blanks to create a nested if that checks if a number is negative, odd, and less than -10.

C Sharp (C#)
int number = -15;
if (number [1] 0)
{
    if (number [2] 2 != 0)
    {
        if (number [3] -10)
        {
            Console.WriteLine("Negative, odd, and less than -10");
        }
    }
}
Drag options to blanks, or click blank then click option'
A<
B%
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for negativity check.
Using wrong operator for odd check.
Using '>' instead of '<' for the last condition.