To print the alphabet from A to Z (capital letters) in C, you can use a loop and the ASCII values of the characters. Here’s an example:
#include <stdio.h> int main() { char letter; printf("Alphabets from A to Z:\n"); for (letter = 'A'; letter <= 'Z'; letter++) { printf("%c ", letter); } printf("\n"); return 0; }
In this code, we initialize the letter
variable with the character ‘A’. Then, we use a for
loop to iterate from ‘A’ to ‘Z’. Inside the loop, we print each character using the %c
format specifier, and then add a space to separate the letters. Finally, we print a newline character (\n
) to move to the next line after printing all the letters.
When you run this program, it will output:
Alphabets from A to Z: 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
This code takes advantage of the fact that the ASCII values of capital letters ‘A’ to ‘Z’ are consecutive, so we can use the comparison operator (<=
) to iterate through them.