ASCII Table in C
0 375
The ASCII (American Standard Code for Information Interchange) table represents a character encoding standard for digital communication.
In C, you can print the ASCII table using loops to display characters and their corresponding ASCII values.
Programs:
Program to Print ASCII Table with Decimal Values
#include<stdio.h>int main() { int i; printf("ASCII Table with Decimal Values:\n"); for(i = 0; i <= 130; i++) { printf("%d: %c\n", i, i); } return 0; }
Output:
ASCII Table with Decimal Values: 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: ! 34: " 35: # 36: $ 37: % 38: & 39: ' 40: ( 41: ) 42: * 43: + 44: , 45: - 46: . 47: / 48: 0 49: 1 50: 2 51: 3 52: 4 53: 5 54: 6 55: 7 56: 8 57: 9 58: : 59: ; 60: < 61: = 62: > 63: ? 64: @ 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: [ 92: \ 93: ] 94: ^ 95: _ 96: ` 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 123: { 124: | 125: } 126: ~ 127: 128: � 129: � 130: �
Program to Print ASCII Table with Hexadecimal Values
#include<stdio.h>int main() { int i; printf("ASCII Table with Hexadecimal Values:\n"); for(i = 0; i <= 130; i++) { printf("%d: 0x%x\n", i, i); } return 0; }
Output:
ASCII Table with Hexadecimal Values: 0: 0x0 1: 0x1 2: 0x2 3: 0x3 4: 0x4 5: 0x5 6: 0x6 7: 0x7 8: 0x8 9: 0x9 10: 0xa 11: 0xb 12: 0xc 13: 0xd 14: 0xe 15: 0xf 16: 0x10 17: 0x11 18: 0x12 19: 0x13 20: 0x14 21: 0x15 22: 0x16 23: 0x17 24: 0x18 25: 0x19 26: 0x1a 27: 0x1b 28: 0x1c 29: 0x1d 30: 0x1e 31: 0x1f 32: 0x20 33: 0x21 34: 0x22 35: 0x23 36: 0x24 37: 0x25 38: 0x26 39: 0x27 40: 0x28 41: 0x29 42: 0x2a 43: 0x2b 44: 0x2c 45: 0x2d 46: 0x2e 47: 0x2f 48: 0x30 49: 0x31 50: 0x32 51: 0x33 52: 0x34 53: 0x35 54: 0x36 55: 0x37 56: 0x38 57: 0x39 58: 0x3a 59: 0x3b 60: 0x3c 61: 0x3d 62: 0x3e 63: 0x3f 64: 0x40 65: 0x41 66: 0x42 67: 0x43 68: 0x44 69: 0x45 70: 0x46 71: 0x47 72: 0x48 73: 0x49 74: 0x4a 75: 0x4b 76: 0x4c 77: 0x4d 78: 0x4e 79: 0x4f 80: 0x50 81: 0x51 82: 0x52 83: 0x53 84: 0x54 85: 0x55 86: 0x56 87: 0x57 88: 0x58 89: 0x59 90: 0x5a 91: 0x5b 92: 0x5c 93: 0x5d 94: 0x5e 95: 0x5f 96: 0x60 97: 0x61 98: 0x62 99: 0x63 100: 0x64 101: 0x65 102: 0x66 103: 0x67 104: 0x68 105: 0x69 106: 0x6a 107: 0x6b 108: 0x6c 109: 0x6d 110: 0x6e 111: 0x6f 112: 0x70 113: 0x71 114: 0x72 115: 0x73 116: 0x74 117: 0x75 118: 0x76 119: 0x77 120: 0x78 121: 0x79 122: 0x7a 123: 0x7b 124: 0x7c 125: 0x7d 126: 0x7e 127: 0x7f 128: 0x80 129: 0x81 130: 0x82Program for ASCII value using octal
#include<stdio.h>int main() { int i; printf("ASCII Table with Octal Values:\n"); for(i = 0; i <= 130; i++) { printf("%d: 0%o\n", i, i); } return 0; }
Output:
ASCII Table with Octal Values: 0: 00 1: 01 2: 02 3: 03 4: 04 5: 05 6: 06 7: 07 8: 010 9: 011 10: 012 11: 013 12: 014 13: 015 14: 016 15: 017 16: 020 17: 021 18: 022 19: 023 20: 024 21: 025 22: 026 23: 027 24: 030 25: 031 26: 032 27: 033 28: 034 29: 035 30: 036 31: 037 32: 040 33: 041 34: 042 35: 043 36: 044 37: 045 38: 046 39: 047 40: 050 41: 051 42: 052 43: 053 44: 054 45: 055 46: 056 47: 057 48: 060 49: 061 50: 062 51: 063 52: 064 53: 065 54: 066 55: 067 56: 070 57: 071 58: 072 59: 073 60: 074 61: 075 62: 076 63: 077 64: 0100 65: 0101 66: 0102 67: 0103 68: 0104 69: 0105 70: 0106 71: 0107 72: 0110 73: 0111 74: 0112 75: 0113 76: 0114 77: 0115 78: 0116 79: 0117 80: 0120 81: 0121 82: 0122 83: 0123 84: 0124 85: 0125 86: 0126 87: 0127 88: 0130 89: 0131 90: 0132 91: 0133 92: 0134 93: 0135 94: 0136 95: 0137 96: 0140 97: 0141 98: 0142 99: 0143 100: 0144 101: 0145 102: 0146 103: 0147 104: 0150 105: 0151 106: 0152 107: 0153 108: 0154 109: 0155 110: 0156 111: 0157 112: 0160 113: 0161 114: 0162 115: 0163 116: 0164 117: 0165 118: 0166 119: 0167 120: 0170 121: 0171 122: 0172 123: 0173 124: 0174 125: 0175 126: 0176 127: 0177 128: 0200 129: 0201 130: 0202
Program 1: Prints the ASCII table with decimal values ranging from 0 to 130.
Program 2: Prints the ASCII table with hexadecimal values. The format specifier %x is used to print in hexadecimal.
Program 3: Prints the ASCII table with octal values. The format specifier %o is used to print in octal.
In each program, a for loop iterates from 0 to 130, printing each ASCII value along with its corresponding character.
Share:
Comments
Waiting for your comments