here's a C++ program that does that:
#include <iostream>
using namespace std;
using namespace std;
int main() {
char c;
cout << "Enter a character: ";
cin >> c;
cout << "The ASCII value of " << c << " is " << int(c) << endl;
return 0;
}
Output:
Enter a character: A
The ASCII value of A is 65
Explanation:
- We start by including the necessary headers and using the std namespace.
- In the main function, we declare a variable c of type char, which will store the character input by the user.
- We prompt the user to enter a character by printing the message "Enter a character: " on the console using the cout object.
- We read the character entered by the user using the cin object and store it in the variable c.
- We use the int() function to convert the char value of c to its corresponding ASCII value, and then we print it on the console using the cout object.
- We return 0 to indicate that the program has executed successfully.
No comments:
Post a Comment
If you have any doubts, please let me know