Program to print ASCII Value of a character
Given a character, we need to print its ASCII value in C/C++/Java/Python.
Examples :
Input : a Output : 97 Input : D Output : 68
Here are few methods in different programming languages to print ASCII value of a given character :
- Python code using ord function :
ord() : It coverts the given string of length one, return an integer representing the unicode code point of the character. For example, ord(‘a’) returns the integer 97.Output:
The ASCII value of g is 103
- C code: We use format specifier here to give numeric value of character. Here %d is used to convert character to its ASCII value.
Output:
The ASCII value of k is 107
- C++ code: Here int() is used to convert character to its ASCII value.
Output:
The ASCII value of A is 65
- Java code : Here, to find the ASCII value of c, we just assign c to an int variable ascii. Internally, Java converts the character value to an ASCII value.
- C# code : Here, to find the ASCII value of c, we just assign c to an int variable ascii. Internally, C# converts the character value to an ASCII value.
Output:
The ASCII value of e is 101
No comments:
Post a Comment
Your feedback is highly appreciated and will help us to improve our content.