Program to display a-z characters using While loop
- Write a program to display a-z characters using While loop in C
- Write a program to display a-z characters using While loop in C++
- Write a program to display a-z characters using While loop in Python
- Write a program to display a-z characters using While loop in PHP
- Write a program to display a-z characters using While loop in Java
- Write a program to display a-z characters using While loop in Java Script
- Write a program to display a-z characters using While 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
- Loop through ASCII values from 97 (for ‘a’) to 122 (for ‘z’)
- Convert the ASCII value to its corresponding character using casting or the appropriate method in the programming language.
- Print the characters.
Program to display a-z characters using While loop
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { char ch = 'a'; while (ch <= 'z') { printf("%c ", ch); ch++; } printf("\n"); return 0; }
#include <iostream> using namespace std; int main() { char ch = 'a'; while (ch <= 'z') { cout << ch << " "; ch++; } cout << endl; return 0; }
ch = 'a' while ch <= 'z': print(ch, end=" ") ch = chr(ord(ch) + 1) print()
<?php $ch = 'a'; while ($ch <= 'z') { echo $ch . " "; $ch++; } echo "\n"; ?>
public class Alphabet { public static void main(String[] args) { char ch = 'a'; while (ch <= 'z') { System.out.print(ch + " "); ch++; } System.out.println(); } }
let ch = 'a'; while (ch <= 'z') { console.log(ch); ch = String.fromCharCode(ch.charCodeAt(0) + 1); }
using System; class Program { static void Main() { char ch = 'a'; while (ch <= 'z') { Console.Write(ch + " "); ch++; } Console.WriteLine(); } }