Program to display a-z characters using For loop

Program to display a-z characters using For loop

  • Write a program to display a-z characters using For loop in C
  • Write a program to display a-z characters using For loop in C++
  • Write a program to display a-z characters using For loop in Python
  • Write a program to display a-z characters using For loop in PHP
  • Write a program to display a-z characters using For loop in Java
  • Write a program to display a-z characters using For loop in Java Script
  • Write a program to display a-z characters using For loop in C#

Explanation:

Using a for loop, you can use the characters’ ASCII values to show the letters a through z. ‘a’ and ‘z’ have ASCII values of 97 and 122, respectively. You can print the matching characters by iterating through these values.

Logic

  1. Loop through ASCII values from 97 (for ‘a’) to 122 (for ‘z’)
  2. Convert the ASCII value to its corresponding character using casting or the appropriate method in the programming language.
  3. Print the characters.

Program to display a-z characters using For loop

#include <stdio.h>

int main() {
    for (char c = 'a'; c <= 'z'; c++) {
        printf("%c\n", c);
    }
    return 0;
}

#include <iostream>
using namespace std;

int main() {
    for (char c = 'a'; c <= 'z'; c++) {
        cout << c << endl;
    }
    return 0;
}

for c in range(ord('a'), ord('z') + 1):
    print(chr(c))

<?php
for ($c = 'a'; $c <= 'z'; $c++) {
    echo $c . "\n";
}
?>

public class DisplayAlphabets {
    public static void main(String[] args) {
        for (char c = 'a'; c <= 'z'; c++) {
            System.out.println(c);
        }
    }
}

for (let c = 'a'.charCodeAt(0); c <= 'z'.charCodeAt(0); c++) {
    console.log(String.fromCharCode(c));
}

using System;

class Program {
    static void Main() {
        for (char c = 'a'; c <= 'z'; c++) {
            Console.WriteLine(c);
        }
    }
}

List of All Programs