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

Checked and unchecked arithmetic 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 enable overflow checking for the addition.

C Sharp (C#)
checked {
    int result = 1000000 [1] 3000;
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to use the checked block for overflow detection.
2fill in blank
medium

Complete the code to disable overflow checking for the multiplication.

C Sharp (C#)
unchecked {
    int result = 20000 [1] 2000;
}
Drag options to blanks, or click blank then click option'
A-
B/
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
Expecting overflow exceptions inside unchecked blocks.
3fill in blank
hard

Fix the error in the code to correctly check for overflow during subtraction.

C Sharp (C#)
checked {
    int result = 1000 [1] 2000;
}
Drag options to blanks, or click blank then click option'
A+
B/
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of subtraction.
Not using checked block for overflow detection.
4fill in blank
hard

Fill both blanks to create a dictionary with keys as numbers and values as their squares, using checked arithmetic for multiplication and a condition to include only squares less than 100.

C Sharp (C#)
var squares = new Dictionary<int, int> {
    { [1], checked([1] [2] [1]) }
};
Drag options to blanks, or click blank then click option'
A5
B*
C10
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number other than 5 for the key.
Using addition or division instead of multiplication.
5fill in blank
hard

Fill all three blanks to create a checked block that divides two numbers and assigns the result to a variable.

C Sharp (C#)
checked {
    int result = [1] [2] [3];
}
Drag options to blanks, or click blank then click option'
A100
B/
C5
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of division.
Swapping the numbers causing wrong division.