Home
C Examples
How To Print Alphabet From a-z (Small Letters) in C Programming | C Programming Examples - 8
Subscribe to:
Post Comments (Atom)
CodeShikhi - The World for Programmers, প্রোগ্রামিং,Learn Programming,Learn Javascirpt | C | C++ | Python | OOP,Learn Programming in Bangla,Bangla Programming Tutorial,Leetcode Problem Solution,BEE Problem Solution,C Programming in Bangla,C in Bangla,Javascript tutorials,C Programming Bangla Tutorial, URI Online Judge Solution in C C++ Python,JavaScript Full Tutorials , OOP Tutorial in C++, Object Oriented Programming in C++,Learn OOP in C++,C Programming Exercise,C Programming Example with Code
// C program to find the print
// Alphabets from a to z
#include <stdio.h>
int main()
{
// Declare the variables
char ch;
printf("The Alphabets from a to z are: \n");
// Traverse each character
for (ch = 'a'; ch <= 'z'; ch++) {
// Print the alphabet
printf("%c ", ch);
}
return 0;
}
The Alphabets from a to z are: 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
Declare a character variable, say ch .
Initialize loop counter variable from ch = 'a' , that goes till ch <= 'z' , increment the loop by 1 in each iteration. The loop structure should look like for(ch='a'; ch<='z'; ch++) .
Inside the loop body print the value of ch .
#include<stdio.h>
int main()
{
int i;
printf("The Alphabets from a to z are: \n");
for(i=97;i<=122;i++)
{
printf("%c",i);
}
}
The Alphabets from a to z are: 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
Here we declared an integer i.
Now this program is same as printing numbers from 97 to 122.
But if you can remember the "ASCII" values of 97 which resembles 'a' and 122 which resembles 'z' as in ascii sheet. To refer ASCII Values click here.
So instead of "%d " if we use "%c" it is converted to ascii value.
Next Post:
How To Print Even or Odd Numbers in C Programming | C Programming Examples - 9
Previous Post:
Good article❤️
ReplyDelete