Problem statement:- Program to print the ascii value of a character.
Data requirement:-
Input Data:- ch
Output Data:-ch, ascii
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:
ch=input("Enter a character:")
ascii=ord(ch) #ord is used for returning the ASCII value a character, ord stands for ordinalprint("The ASCII value is",ascii)
Input/Output:
Enter a character:b
The ASCII value is 98
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box