ADVERTISEMENT
Alphabets from a to z
This C program prints the lowercase English alphabet in a continuous sequence.
#include<stdio.h>
main()
{
int i;
for(i=97;i<=122;i++)
{
printf("%c",i);
}
printf("\n");
}
C Programming ExamplesExplanation:
Here’s a step-by-step explanation of the code:
Header File:
- The program includes the standard C library header <stdio.h>. This header is required for input and output operations.
Main Function:
- The main function is the entry point of the program, where the execution starts.
Variable Declaration:
- The program declares an integer variable ‘i’ that will be used as a loop counter.
Printing Lowercase Alphabets:
- The program uses a for loop to iterate through the ASCII values of lowercase English letters from ‘a’ (ASCII 97) to ‘z’ (ASCII 122).
- The loop initialization (i=97) sets ‘i’ to the ASCII value of ‘a’.
- The loop condition (i<=122) checks if ‘i’ is less than or equal to the ASCII value of ‘z’.
- If the condition is true, the loop body is executed.
- Inside the loop, printf is used to print the character represented by the ASCII value ‘i. In this case, ‘i’ is the ASCII value of a lowercase letter, and %c is used as the format specifier to print it as a character.
- This line effectively prints the lowercase alphabet characters one by one, from ‘a’ to ‘z’.
Newline Character:
- After printing all the lowercase alphabet characters, the program uses printf with “\n” to print a newline character. This adds a line break, moving the cursor to the beginning of the next line.
End of Program:
- The program reaches the end of the main function and, consequently, the end of the program’s execution.
This code uses a for loop to print the lowercase English alphabet, one character at a time, starting from ‘a’ and ending with ‘z’. It separates each letter with a space and adds a newline character at the end to create a list of lowercase letters in alphabetical order.