Thuta Learning
ExercisesProgrammingbeginner

Practice Exercises: Fundamentals

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Work through Practice Exercises: Fundamentals hands-on
  • Practice the skills you've already learned to make them stick
  • Get better at finding bugs, fixing them, and checking your own work

Let's think about this for a second

This exercise set is designed to help you revisit and practice the variables, operators, if/else, loops, and arrays concepts covered in the Basic chapter. There's no new teaching here — just a chance to actually write code using the syntax you've already learned. Treat each task as its own little project: create a new console app for it and run it. The tasks are simple, but writing and running the syntax hands-on will help it stick in your memory far better than just reading about it.

Exercises

(1) Print only the even numbers from 1 to 50 using a for loop. (2) Create an integer array (say, 6 elements) and use a foreach loop to find the sum and average of the numbers in the array. (3) Read a user-entered age with Console.ReadLine() and use if/else if/else to categorize it as "Child", "Teenager", or "Adult". (4) Read a string from the user and use a loop to count both the total number of characters and the number of vowels (a, e, i, o, u) in it.

Code Example

csharp
// Task 1 starter
for (int i = 1; i <= 50; i++)
{
    if (i % 2 == 0)
    {
        Console.WriteLine(i);
    }
}

// Task 2 starter
int[] numbers = { 4, 8, 15, 16, 23, 42 };
int sum = 0;
foreach (int n in numbers)
{
    sum += n;
}
double average = (double)sum / numbers.Length;
Console.WriteLine($"Sum: {sum}, Average: {average}");

// Task 3 starter
Console.Write("Enter age: ");
int age = int.Parse(Console.ReadLine());
// if / else if / else ဖြင့် Child / Teenager / Adult ခွဲပါ

// Task 4 starter
Console.Write("Enter a sentence: ");
string text = Console.ReadLine();
int vowelCount = 0;
// loop သုံးပြီး vowel count ကို တွက်ပါ
You should see
All four tasks will print correct results to the console: the list of even numbers, the sum/average, the age category, and the vowel count.

5-Minute Challenge

Modify Task 2 so it also finds the largest and smallest numbers in the array — but without using Math.Max/Math.Min, using a loop instead (5 minutes).

A Quick Heads-Up

Remember that integer division (int / int) only returns an int result — don't forget to cast to (double) for calculations like averages or percentages.

Easy traps

  • Using int.Parse() directly without considering that it throws an exception if the user's input isn't a number
  • Doing int/int division without casting to double for an average, losing the decimal point and getting the wrong result

Now Try It Yourself

Modify Task 2 so it also finds the largest and smallest numbers in the array — but without using Math.Max/Math.Min, using a loop instead (5 minutes).

You'll know it worked when: All four tasks will print correct results to the console: the list of even numbers, the sum/average, the age category, and the vowel count.

Practice Exercises: Fundamentals | Thuta Learning