Program to Find ASCII value of a character

Description

Use format specifier to give numeric value of character.
%d is used to convert character to its ASCII value.

C/C++

/* C Program to Find ASCII value of a character */
//Save it as FindASCII.c

#include<stdio.h>
int main(){

    char data;

    printf("Enter the character : ");
    scanf("%c",&data);

    printf("The ascii of %c is %d",data, data);

    return 0;
}
Input:
Enter the character : 
A
Output:
The ascii of A is 65

Java

/* Java Program to Find ASCII value of a character */
//Save it as FindASCII.java

import java.io.*;
import java.util.Scanner;

public class FindASCII {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the character : ");
        char data = scanner.next().trim().charAt(0);
        
        int findASCII = (int)data;

        System.out.println("The ascii of "+data+" is "+findASCII);
    }
}
Input:
Enter the character : 
A

Output:
The ascii of A is 65

Related Programs

1) Program to calculate Grade of Student
2) Program to find sum of digits of a number
3) Program to reverse a number
4) Program to display multiplication table of a number
5) Program to find sum of first and last digit of a number
6) Program to find factors of a Number
7) Program to find largest and smallest digit in a Number
8) Program to add two complex numbers
9) Program to calculate Volume and Surface Area of Sphere
10) Program to Check Leap Year
11) Program to find largest and smallest character in a String
12) Program to Check Whether a Character is a Vowel or Not
Share Me

Leave a Reply