C Program to print all ASCII values.


Problem

Print the American Standard Code for Information Interchange (ASCII) values of 0 to 255 characters without initializing the character to integer type variable. Simply, use the format specifier.

Solution

Here we are writing a program to print only from 65 to 122.

If you want to see all ASCII values, in for loop you can write as follows −

For(i=0;i<255;i++)

Then, it prints all the ASCII values from 0 to 255.

The logic used to print the ASCII values from 65 to 122 is as follows −

Prints ASII values From A to z
for (i = 65; i < =122; i++){
   printf("%c \t\t %d
", i, i); }

Example

Following is the C program to print the ASCII values from 65 to 122 −

 Live Demo

#include <stdio.h>
int main() {
   // Declare Variables
   int i = 0;
   printf("Character \t ASCII Value

");    //Print ASCII Values    for (i = 65; i <=122; i++) {       printf("%c \t\t %d
", i, i);    }    return 0; }

Output

When the above program is executed, it produces the following output −

Character ASCII Value

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
[ 91
\ 92
] 93
^ 94
_ 95
` 96
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

Updated on: 25-Mar-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements