- C program to display characters from a to z using loop.
- We can print all alphabets starting from A to Z using for loop.
- Take a char variable and using for loop iterate it from A to Z.
- Let us see an Example C program to print A to Z using for loop.
Program #1: Write a C program to print or display characters from A to Z using for loop.
- #include <stdio.h>
- int main()
- {
- char c;
- for(c = 'A'; c <= 'Z'; ++c)
- printf("%c ", c);
- return 0;
- }
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
Program #2: Write a C Program to Display English Alphabets in Uppercase and Lowercase
- #include <stdio.h>
- int main()
- {
- char c;
- printf("Enter u to display alphabets in uppercase. And enter l to display alphabets in
- lowercase: ");
- scanf("%c", &c);
- if(c== 'U' || c== 'u')
- {
- for(c = 'A'; c <= 'Z'; ++c)
- printf("%c ", c);
- }
- else if (c == 'L' || c == 'l')
- {
- for(c = 'a'; c <= 'z'; ++c)
- printf("%c ", c);
- }
- else
- printf("Error! You entered invalid character.");
- getch();
- }
Output:
No comments