ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
Code Snippets C/C++ Code Snippets

C program to print ASCII values using while loop.

By: IncludeHelp, On 17 OCT 2016

ADVERTISEMENT
ADVERTISEMENT

In this program we will learn how to print ASCII value along with the characters using while loop in c programming language?

Here we will print ASCII value along with the related characters from 32 to 127 using while loop, we will assign 32 to loop counter and run a loop until value will not be 127.

C program (Code Snippet) - Print ASCII of all characters using while loop

Let’s consider the following example:

/*c program to print ascii values using while loop*/

#include <stdio.h>

int main(){
	unsigned char ch;		
	
	ch=32; //start with 32 (space)
	while(ch<=127){
		printf("%c [%03d] ",ch,ch);
		ch++;
	}
	printf("\n");
	
	return 0;
}

Output

      [032] ! [033] " [034] # [035] $ [036] % [037] & [038] ' [039] ( [040] ) [041] * [042] + [043] , [044] - [045] . [046] / [047] 0 [048] 1 [049] 2 [050] 3 [051] 4 [052] 5 [053] 
    6 [054] 7 [055] 8 [056] 9 [057] : [058] ; [059] < [060] = [061] > [062] ? [063] @ [064] A [065] B [066] C [067] D [068] E [069] F [070] G [071] H [072] I [073] J [074] K [075] 
    L [076] M [077] N [078] O [079] P [080] Q [081] R [082] S [083] T [084] U [085] V [086] W [087] X [088] Y [089] Z [090] [ [091] \ [092] ] [093] ^ [094] _ [095] ` [096] a [097] 
    b [098] c [099] 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] { [123] | [124] } [125] ~ [126]  [127]

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.