C# ยท Practice
C# exercises
13 exercises: 5 easy, 5 medium and 3 hard. Each has a starter file, examples, hints and a solution you can reveal, and your program is checked against every test case. Running C# in the browser is not available yet: write your program here, then run it locally against the examples.
- Bakery tray packingEasy
Read a loaf count and print how many full trays of six it fills and how many loaves remain. Practise integer division and modulo in C#.
BasicsNot started
- Conference badgeEasy
Print a three-line attendee badge from a name and an organisation, using ToUpper, string length and a repeated character. A first C# string exercise.
StringsNot started
- Greenhouse alertEasy
Read a greenhouse temperature and print which action the controller takes. Practise if, else if and else with inclusive ranges in C#.
Control flowNot started
- Sensor extremesEasy
Read one line of temperature readings into an array and print the highest, lowest and their difference. Practise Split, int.Parse and array scanning in C#.
Arrays and listsNot started
- Staircase step counterEasy
Print a running total of steps climbed after each flight of stairs. A C# for loop exercise with an accumulator variable.
Control flowNot started
- Garden bed areasMedium
Compute the area of rectangular, square and circular garden beds through a shared abstract base class. Inheritance and polymorphism in C#.
Classes and objectsNot started
- Locker code checkMedium
Validate gym locker codes (two capital letters then four digits) with a bool method that inspects each character. C# methods and char checks.
StringsNot started
- Messy invoice linesMedium
Total the valid lines of a damaged invoice export and count the rejected ones. Read to end of input and handle FormatException in C#.
ExceptionsNot started
- Overdue library feesMedium
Model library loans as objects with a fee calculation, then print each fee and the total. Classes, properties and methods in C#.
Classes and objectsNot started
- Staff per departmentMedium
Group a hospital roster by department with LINQ and list departments from most staffed to least, ties alphabetical. GroupBy, OrderByDescending, ThenBy.
LINQNot started
- Longest affordable stretchHard
Find the most consecutive trail segments whose total climb fits a budget using a sliding window over an int array. A two-pointer exercise in C#.
AlgorithmsNot started
- Market stall bookingsHard
Choose the largest set of non-overlapping stall bookings by sorting on end time and picking greedily. Greedy interval selection in C# with LINQ.
AlgorithmsNot started
- Shelf weight queriesHard
Answer many range-sum questions about a row of warehouse shelves in constant time each by precomputing prefix sums. Arrays and long arithmetic in C#.
AlgorithmsNot started