Print Alphabets A to Z Without Using For Loop in C
In C programming, you can print alphabets from A to Z using a while loop or recursion instead of a for loop.
1. Problem Statement
Write a C program to print all uppercase letters from A to Z without using a for loop.
2. Algorithm
Step 1: Start the program.
Step 2: Initialize a character variable with 'A'.
Step 3: Use a while loop or recursion to print the character until it reaches 'Z'.
Step 4: Increment the character in each iteration.
Step 5: End the program.
3. C Program Using While Loop
C
Print alphabets from A to Z without using for loop
#include <stdio.h>
int main() {
char ch = 'A';
while(ch <= 'Z') {
printf("%c ", ch);
ch++;
}
return 0;
}
4. Output
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Notes
You can use a while loop or recursion to print alphabets without using a for loop. In C, characters can be incremented like numbers because of their ASCII values.
Codecrown