Skip to content

Print Character Of An Ascii Value

Updated: at 10:27 AM

Table of contents

Open Table of contents

Write a program to print character of an ascii value

ASCII value is the numeric representation of a character. For example, the ASCII value of the character ‘A’ is 65. The ASCII value of the character ‘a’ is 97. The ASCII value of the character ‘0’ is 48. The ASCII value of the character ’ ’ is 32.

Input  : 65
Output : A

C

// Write a C program to print character of an ascii value

#include <stdlib.h>
#include <conio.h>

int main(){
    char my_ch;
    printf("Enter A character \n");
    scanf("%c",&my_ch);
    int result=(int)my_ch;
    printf("%d",result);
}

C#

// Write a C# program to print character of an ascii value

using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.Write("Enter ASCII value : ");
        int input = Convert.ToInt32(Console.ReadLine());
        Console.Write("The character is : ");
        Console.Write(Convert.ToChar(input));
    }
}

C++

// Write a C++ program to print character of an ascii value

#include <iostream>
using namespace std;

int main(){
    char ch;
    cout<<"Enter a Character"<<'\n';
    cin>>ch;
    cout<<(int)ch<<'\n';
}

Go

// Write a Go program to print character of an ascii value

package main

import "fmt"

func main() {
  var asciiValue int
  fmt.Println("Enter ASCII value:")
  fmt.Scan(&asciiValue)
	character := rune(asciiValue)

	fmt.Printf("Character corresponding to ASCII Code %d = %c\n", asciiValue, character)
}

Java

// Write a Java program to print character of an ascii value

import java.util.Scanner;

public class PrintCharacterOfAnAsciiValue {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.println("Enter a value to find corresponding character");
        int number = input.nextInt();

        char asciiChar = (char)number;
        System.out.println("The character for ASCII value " + number + " is: " + asciiChar);

        input.close();
    }
  }

Kotlin

// Write a Kotlin program to print character of an ascii value

fun main() {
    var num = 65;
    println(num.toChar())
}

Perl

# Write a Perl program to print character of an ascii value

#!/usr/bin/perl
print chr (65);

PHP

// Write a PHP program to print character of an ascii value

<?php

$str1 = readline();

$char1 = chr($str1);

echo $char1;

?>

Python

# Write a Python program to print character of an ascii value

ascii = int(input())
print(chr(ascii))

Ruby

# Write a Ruby program to print character of an ascii value

def printCharacterOfAnAsciiValue int
    int.chr
end

puts printCharacterOfAnAsciiValue 65

TypeScript

// Write a TypeScript program to print character of an ascii value

function PrintCharacterOfAnAsciiValue(str: string) {
  return str.charCodeAt(0);
}

console.log("Given string is", PrintCharacterOfAnAsciiValue("A"));

Similar programs