Char + For - C# Programming Exercise

In this C# exercise, you are asked to write a program that prints the letters from B to N in uppercase, using a for loop. This type of exercise is perfect for practicing the use of loops and working with characters in C#. The program should iterate from the ASCII value of the letter B to the value of the letter N, printing each letter to the console.

Additionally, by using the for loop, you will learn how to handle indices in iteration and how to work with character sequences. This type of operation is very common in programming, especially when manipulating ranges of characters or numbers.

This exercise is crucial for understanding the logic behind loops and how to use them effectively to perform repetitive tasks, like printing a sequence of characters. It will also help you strengthen your understanding of ASCII values and their relation to characters in programming.

 Category

Basic Data Types

 Exercise

Char + For

 Objective

Write a C# program to write the letters "B" to "N" (uppercase), using "for"

 Write Your C# Exercise

using System;  // Import the System namespace to use basic classes like Console

class Program  // Define the main class of the program
{
    static void Main()  // The entry point of the program
    {
        // Loop through the ASCII values of characters 'B' to 'N'
        for (char letter = 'B'; letter <= 'N'; letter++)  // Start at 'B' and loop until 'N'
        {
            Console.Write(letter);  // Print the current letter
        }

        Console.WriteLine();  // Move to the next line after printing all letters
    }
}

 Share this C# exercise

 More C# Programming Exercises of Basic Data Types

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Double, approximation of Pi

    In this C# exercise, you are asked to write a program that calculates an approximation for PI using the alternating fraction series: pi/4 = 1/1 - 1/3 + 1/5 -...

  •  Perimeter Area

    In this C# exercise, you are asked to write a program that calculates the perimeter, area, and diagonal of a rectangle from its width and height....

  •  Hexadecimal and binary

    In this C# exercise, you are asked to write a program that prompts the user for a number and displays it in both hexadecimal and binary. The program should continue r...

  •  Binary

    In this C# exercise, you are asked to write a program that prompts the user for a decimal number and displays its equivalent in binary. The program should continue re...

  •  Conditional and boolean

    In this C# exercise, you are asked to write a program that uses the conditional operator (also known as the ternary operator) to assign a boolean variable named "bothEven...

  •  Exceptions V2

    In this C# exercise, you are asked to write a program that prompts the user for a real number and displays its square root. Additionally, the program must handle any ...