30 C# Basic Exercises for Intermediate with Solutions

Master intermediate C# skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C#, setting a solid foundation for advanced challenges. Start your journey to C# mastery today!

Learning Objectives:

Master intermediate C# skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C#, setting a solid foundation for advanced challenges. Start your journey to C# mastery today!

Exercise Instructions:

  • Start with the first exercise and attempt to solve it before checking the hint or solution.
  • Ensure you understand the logic behind each solution, as this will help you in more complex problems.
  • Use these exercises to reinforce your learning and identify areas that may require further study.

1. Write a program to calculate the sum of all prime numbers between two hardcoded numbers.

Required Input:

Range: 10 to 30

Expected Output:

Sum of Prime Numbers: 112

Code In C#

using System; class PrimeSum { static void Main() { // Calculate the sum of all prime numbers in the range } }

Run Code?

Click Run Button to view compiled output

2. Create a program to check if a given string is an anagram of another hardcoded string.

Required Input:

Strings: "listen" and "silent"

Expected Output:

Is Anagram: True

Code In C#

using System; class CheckAnagram { static void Main() { // Check if the two strings are anagrams } }

Run Code?

Click Run Button to view compiled output

3. Write a program to find the second smallest number in a hardcoded array.

Required Input:

Array: [4, 2, 9, 1, 5]

Expected Output:

Second Smallest: 2

Code In C#

using System; class SecondSmallest { static void Main() { // Find the second smallest number in the array } }

Run Code?

Click Run Button to view compiled output

4. Create a program to remove all vowels from a hardcoded string and print the result.

Required Input:

String: "programming"

Expected Output:

String without Vowels: prgrmmng

Code In C#

using System; class RemoveVowels { static void Main() { // Remove vowels from the string } }

Run Code?

Click Run Button to view compiled output

5. Write a program to count the frequency of each element in a hardcoded array.

Required Input:

Array: [1, 2, 2, 3, 1, 4]

Expected Output:

Frequencies:
1: 2
2: 2
3: 1
4: 1

Code In C#

using System; using System.Collections.Generic; class FrequencyCounter { static void Main() { // Count the frequency of elements in the array } }

Run Code?

Click Run Button to view compiled output

6. Create a program to generate all permutations of a hardcoded string.

Required Input:

String: "abc"

Expected Output:

Permutations:
abc
acb
bac
bca
cba
cab

Code In C#

using System; class StringPermutations { static void Main() { // Generate all permutations of the string } }

Run Code?

Click Run Button to view compiled output

7. Write a program to check if a hardcoded 2D array is symmetric along its diagonal.

Required Input:

Matrix:
[ [1, 2, 3],
 [2, 4, 5],
 [3, 5, 6] ]

Expected Output:

Is Symmetric: True

Code In C#

using System; class SymmetricMatrix { static void Main() { // Check if the matrix is symmetric along its diagonal } }

Run Code?

Click Run Button to view compiled output

8. Create a program to sort a hardcoded array in descending order without using built-in methods.

Required Input:

Array: [5, 2, 9, 1, 7]

Expected Output:

Sorted Array: 9, 7, 5, 2, 1

Code In C#

using System; class DescendingSort { static void Main() { // Sort the array in descending order } }

Run Code?

Click Run Button to view compiled output

9. Write a program to calculate the sum of digits of all numbers in a hardcoded array.

Required Input:

Array: [123, 45, 67]

Expected Output:

Sum of Digits: 28

Code In C#

using System; class SumOfDigitsInArray { static void Main() { // Calculate the sum of digits of all numbers in the array } }

Run Code?

Click Run Button to view compiled output

10. Create a program to calculate the product of all odd numbers in a hardcoded array.

Required Input:

Array: [1, 2, 3, 4, 5]

Expected Output:

Product of Odd Numbers: 15

Code In C#

using System; class ProductOfOddNumbers { static void Main() { // Calculate the product of all odd numbers in the array } }

Run Code?

Click Run Button to view compiled output

ad vertical

1 of 4