Monday, April 28, 2025

C Program - Display All Alphabets And SKIP Special Characters

This is a C program that displays the ASCII codes and corresponding characters for all the alphabets in the English language.  

#include <stdio.h>

int main()
{

    int x;

    for (x = 65; x <= 122; x++)
    {
        if (x != 91 &&
                x != 92 &&
                x != 93 &&
                x != 94 &&
                x != 95 &&
                x != 96)
        {
            printf("%d <--> %c \n", x, x);
        }
        else
        {
            printf("%d <--> %c character is not an alphabet. \n ", x, x);
        }
    }

    return 0;
}

Result: 

65 <--> A
66 <--> B
67 <--> C
68 <--> D
69 <--> E
70 <--> F
71 <--> G
72 <--> H
73 <--> I
74 <--> J
75 <--> K
76 <--> L
77 <--> M
78 <--> N
79 <--> O
80 <--> P
81 <--> Q
82 <--> R
83 <--> S
84 <--> T
85 <--> U
86 <--> V
87 <--> W
88 <--> X
89 <--> Y
90 <--> Z
91 <--> [ character is not an alphabet.
 92 <--> \ character is not an alphabet.
 93 <--> ] character is not an alphabet.
 94 <--> ^ character is not an alphabet.
 95 <--> _ character is not an alphabet.
 96 <--> ` character is not an alphabet.
 97 <--> a
98 <--> b
99 <--> c
100 <--> d
101 <--> e
102 <--> f
103 <--> g
104 <--> h
105 <--> i
106 <--> j
107 <--> k
108 <--> l
109 <--> m
110 <--> n
111 <--> o
112 <--> p
113 <--> q
114 <--> r
115 <--> s
116 <--> t
117 <--> u
118 <--> v
119 <--> w
120 <--> x
121 <--> y
122 <--> z

Process returned 0 (0x0)   execution time : 0.073 s
Press any key to continue.

Here's a detailed explanation of the code, line by line: 

#include <stdio.h>

This line includes the standard input-output library in C programming.

int main()
{
    int x;

This is the main function of the program. It declares an integer variable x

    for (x = 65; x <= 122; x++)
    {

This is a for loop that starts with x being assigned a value of 65, which is the ASCII code for the uppercase letter "A". The loop will continue as long as x is less than or equal to the ASCII code for the lowercase letter "z", which is 122. 

        if (x != 91 && x != 92 && x != 93 && x != 94 && x != 95 && x != 96)
        {
            printf("%d <--> %c \n", x, x);
        }

This block of code uses if statements to check if x is not one of the ASCII codes for the non-alphabetic characters '[', '', ']', '^', '_', and ''. If xis not one of these characters, theprintf()function will print the ASCII code and the corresponding character using the%dand%c` format specifiers. 

        else
        {
            printf("%d <--> %c character is not an alphabet. \n ", x, x);
        }

If x is one of the non-alphabetic characters, the printf() function will print the ASCII code and the corresponding character along with the message "character is not an alphabet". 

    }
    return 0;
}

This is the end of the for loop. After the loop is completed, the program ends with a return value of 0.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...