This C code block is a program that prints the ASCII codes and corresponding characters for uppercase and lowercase alphabets.
#include <stdio.h>
int main()
{
char char_atm;
printf("----------- \n");
printf("Uppercase: \n");
printf("----------- \n");
for (char_atm = 'A'; char_atm <= 'Z'; char_atm++)
{
printf("%d <--> %c \n", char_atm, char_atm);
}
printf("----------- \n");
printf("Loweracse: \n");
printf("----------- \n");
for (char_atm = 'a'; char_atm <= 'z'; char_atm++)
{
printf("%d <--> %c \n", char_atm, char_atm);
}
return 0;
}
Result:
-----------
Uppercase:
-----------
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
-----------
Loweracse:
-----------
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.109 s
Press any key to continue.
Let's go through it line by line:
#include <stdio.h>
This line includes the standard input/output header file.
int main()
{
This line defines the main function of the program.
char char_atm;
This line declares a character variable char_atm
which will be used to store the alphabets.
printf("----------- \n");
printf("Uppercase: \n");
printf("----------- \n");
These lines print a header indicating the following output will show the ASCII codes and corresponding characters for uppercase alphabets.
for (char_atm = 'A'; char_atm <= 'Z'; char_atm++)
{
printf("%d <--> %c \n", char_atm, char_atm);
}
This for
loop iterates through each uppercase alphabet from 'A' to 'Z', and for each alphabet, it prints the corresponding ASCII code and character using the printf()
function. %d
represents the ASCII code and %c
represents the corresponding character.
printf("----------- \n");
printf("Loweracse: \n");
printf("----------- \n");
These lines print a header indicating the following output will show the ASCII codes and corresponding characters for lowercase alphabets.
for (char_atm = 'a'; char_atm <= 'z'; char_atm++)
{
printf("%d <--> %c \n", char_atm, char_atm);
}
This for
loop iterates through each lowercase alphabet from 'a' to 'z', and for each alphabet, it prints the corresponding ASCII code and character using the printf()
function. %d
represents the ASCII code and %c
represents the corresponding character.
return 0;
}
This line indicates the end of the main()
function and returns 0, indicating that the program has executed successfully.
No comments:
Post a Comment