Here's a C program to print the alphabets with their ASCII values with output and explanation. This program uses C concepts like IF-ELSE Condition, Continue Statement and For Loops.
ASCII code: American Standard Code for Information Interchange or ASCII code is a standard character set for computer. In simple words, every character and symbol is given an integer value which is known as ASCII value of that character.
# include <stdio.h> # include <conio.h> void main() { char ch ; clrscr() ; printf("ASCII chart for characters : \n\n") ; for(ch = 65 ; ch <= 122 ; ch++) { if(ch > 90 && ch < 97) continue ; printf("%c \t %3d \t", ch, ch) ; } getch() ; }
Output of above program
ASCII chart for characters :
A 65 B 66 C 67 D 68 E 69
F 70 G 71 H 72 I 73 J 74
K 75 L 76 M 77 N 78 O 79
P 80 Q 81 R 82 S 83 T 84
U 85 V 86 W 87 X 88 Y 89
Z 90 a 97 b 98 c 99 d 100
e 101 f 102 g 103 h 104 i 105
j 106 k 107 l 108 m 109 n 110
o 111 p 112 q 113 r 114 s 115
t 116 u 117 v 118 w 119 x 120
y 121 z 122
Explanation of above program
This program is a good example to show flexibility of C programming. You must be knowing that -
- To print an integer value you use %d.
- To print a character value you use %c.
But what will happen if you try to print a character's value using %d???
Answer to that is very simple. When you try to print a character's value using %d, that character's ASCII value gets printed instead of the character itself.
Now lets look at the program. In this program, ASCII table is printed using FOR loop. This FOR loop runs for loop variable ch = 65 to 122, incrementing value of ch after each iteration.
Since in ASCII table, alphabets ranging from A - Z have values in the range 65 - 90 and alphabets ranging from a - z have values in the range - 97 - 122. So using IF statement and CONTINUE statement inside FOR loop, we are skipping FOR loop's execution after IF statement for ch = 91 to 96.
Using print statement inside FOR loop, we are printing first the character itself using %c and then ASCII value corresponding to that character using %d.
Hi There,
Great post. Well though out. This piece reminds me when I was starting out C Programming Tutorial graduating from college.
I am working LDPC encoding and decoding for mini project work. With my effort I have completed LDPC encoding but struggling with LDPC decoding. I need to complete this project complete this project within short period so please help me.
I don`t know how to start decoding algorithm in C language but i do have algorithm. So, can anyone help me in writing C language for decoding procedure.
Thank you very much and will look for more postings from you.
Thank you,
Nani