Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Print all ASCII character with their values

C++ For Loop: Exercise-61 with Solution

Write a program in C++ to print all ASCII character with their values.

Pictorial Presentation:

C++ Exercises: Print all ASCII character with their values

Sample Solution:-

C++ Code :

#include <iostream>
using namespace std;
int main()
{
    int sn, en, i, j, ctr, r;
    cout << "\n\n Print ASCII character with their values:\n";
    cout << "-------------------------------------------------\n";
    cout << " Input the starting value for ASCII characters: ";
    cin >> sn;
    cout << " Input the ending value for ASCII characters: ";
    cin >> en;	
	if (sn>255 || sn<0)
	sn=1;
	if(en<0 || en>255)
	en=255;
	cout << "The ASCII characters:"<<endl ;
    for (i = sn; i <=en; i++) 
    {
        cout << i<<" --> "<<char(i)<<endl;
    }
}

Sample Output:

 Print ASCII character with their values:                              
-------------------------------------------------                      
 Input the starting value for ASCII characters: 65                     
 Input the ending value for ASCII characters: 75                       
The ASCII characters:                                                  
65 --> A                                                               
66 --> B                                                               
67 --> C                                                               
68 --> D                                                               
69 --> E                                                               
70 --> F                                                               
71 --> G                                                               
72 --> H                                                               
73 --> I                                                               
74 --> J                                                               
75 --> K 

Flowchart:

Flowchart: Print all ASCII character with their values

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to input any number and print it in words.
Next: Write a program in C++ to find power of any number using for loop.

What is the difficulty level of this exercise?