Write a program to print the ASCII value of a given character.
Example:
Input: ch = 'A' Output: ASCII value of character is 65
Approach
C
#include <stdio.h>int main(){char ch;printf("Enter a character: ");scanf("%c", &ch);printf("ASCCI value of character is %d", ch);return 0;}
Java
import java.util.Scanner;public class AsciiChar {public static void main(String[] args) {System.out.println("Enter a character: ");Scanner sc = new Scanner(System.in);char ch = sc.nextLine().charAt(0);System.out.printf("ASCCI value of character is %d", (int) ch);sc.close();}}
No comments:
Post a Comment