Program to print ascii value of a character

Problem statement:- Program to print the ascii value of a character.

Data requirement:-

   Input Data:- ch

  Output Data:-ch, ascii

Program in C

Here is the source code of the C Program to print the ascii value of a character.

Code:

#include<stdio.h>
int main()
{
    char ch;
    printf("Enter a character:");
    scanf("%c",&ch);
    int ascii=ch;
    printf("The ASCII value of %c is %d.",ch,ascii);
}

Input/Output:
Enter a character:/
The ASCII value of / is 47.

Program in C++

Here is the source code of the C++ Program to print the ASCII value of a character.

Code:

#include<iostream>
using namespace std;
int main()
{
    char ch;
    cout<<"Enter a character:";
    cin>>ch;
    int ascii=ch;
    cout<<"The ASCII value of "<<ch<<" is "<<ascii;
}

Input/Output:
Enter a character:&
The ASCII value of & is 38

Program in Java

Here is the source code of the Java Program to print the ASCII value of a character.

Code:

import java.util.Scanner;
public class PrintAscii {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
char ch;
    System.out.println("Enter a character:");
    ch=cs.next().charAt(0);
    int ascii=ch;
    System.out.println("The ASCII value of "+ch+" is "+ascii);
    cs.close();
}
}

Input/Output:
Enter a character:
#
The ASCII value of 35 is #

Program in Python

Here is the source code of the Python Program to print the ascii value of a character.

Code:

Post a Comment

0 Comments