C - Print ASCII of All Upper and Lower Case Characters in Decimal and Hexadecimal using C Program.


IncludeHelp 04 August 2016

In this code snippet, we will learn how to print ASCII values of all Upper and Lower case characters in decimal and hexadecimal using c program.

It is very easy to get ASCII value of any character in c language, you have to just print the character value in %d (for decimal) and %x (for hexadecimal).

In this program we used two loops, first loop is running from character 'A' to 'Z' and second loop is running from character ‘a’ to ‘z’. And program is printing the values in %d and %x format.

We used %03d - to pad value with 0 in 3 digits, and %02X – to pad value with 0 in 2 digits, capital X is used to display capital characters in hexadecimal code.

C Code Snippet - Print ASCII Values of All Upper and Lower Case Characters in Decimal and Hexadecimal

/*C - Print ASCII of All Upper and Lower Case Characters 
in Decimal and Hexadecimal using C Program.*/

#include <stdio.h>

int main(){
	char loop;
	
	printf("\nUpper Case Characters:\n");
	for(loop='A';loop<='Z';loop++){
		printf("[%c]- %03d - %02X ",loop,loop,loop);
	}
	
	printf("\nLower Case Characters:\n");
	for(loop='a';loop<='z';loop++){
		printf("[%c]- %03d - %02X ",loop,loop,loop);
	}	
	
	printf("\n");
	return 0;
}

    Upper Case Characters:
    [A]- 065 - 41 [B]- 066 - 42 [C]- 067 - 43 [D]- 068 - 44 
    [E]- 069 - 45 [F]- 070 - 46 [G]- 071 - 47 [H]- 072 - 48 
    [I]- 073 - 49 [J]- 074 - 4A [K]- 075 - 4B [L]- 076 - 4C 
    [M]- 077 - 4D [N]- 078 - 4E [O]- 079 - 4F [P]- 080 - 50 
    [Q]- 081 - 51 [R]- 082 - 52 [S]- 083 - 53 [T]- 084 - 54 
    [U]- 085 - 55 [V]- 086 - 56 [W]- 087 - 57 [X]- 088 - 58 
    [Y]- 089 - 59 [Z]- 090 - 5A
    Lower Case Characters:
    [a]- 097 - 61 [b]- 098 - 62 [c]- 099 - 63 [d]- 100 - 64 
    [e]- 101 - 65 [f]- 102 - 66 [g]- 103 - 67 [h]- 104 - 68 
    [i]- 105 - 69 [j]- 106 - 6A [k]- 107 - 6B [l]- 108 - 6C 
    [m]- 109 - 6D [n]- 110 - 6E [o]- 111 - 6F [p]- 112 - 70 
    [q]- 113 - 71 [r]- 114 - 72 [s]- 115 - 73 [t]- 116 - 74 
    [u]- 117 - 75 [v]- 118 - 76 [w]- 119 - 77 [x]- 120 - 78 
    [y]- 121 - 79 [z]- 122 - 7A



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.