Programa para imprimir valor ASCII de un caracter

Dado un carácter, necesitamos imprimir su valor ASCII en C/C++/Java/Python.

Python

# Python program to print 
# ASCII Value of Character
  
# In c we can assign different
# characters of which we want ASCII value 
  
c = 'g'
# print the ASCII value of assigned character in c
print("The ASCII value of '" + c + "' is", ord(c))

C

// C program to print
// ASCII Value of Character
#include <stdio.h>
int main()
{
    char c = 'k';
  
    // %d displays the integer value of a character
    // %c displays the actual character
    printf("The ASCII value of %c is %d", c, c);
    return 0;
}

CPP

// CPP program to print
// ASCII Value of Character
#include <iostream>
using namespace std;
int main()
{
    char c = 'A';
    cout << "The ASCII value of " << c << " is " << int(c);
    return 0;
}

Java

// Java program to print
// ASCII Value of Character
public class AsciiValue {
  
    public static void main(String[] args)
    {
  
        char c = 'e';
        int ascii = c;
        System.out.println("The ASCII value of " + c + " is: " + ascii);
    }
}

CSHARP

// C# program to print
// ASCII Value of Character
using System;
  
public class AsciiValue 
{
    public static void Main()
    {
  
        char c = 'e';
        int ascii = c;
        Console.Write("The ASCII value of " + 
                        c + " is: " + ascii);
    }
}
  
// This code is contributed 
// by nitin mittal

Python3

print("Enter a String: ", end="")
text = input()
textlength = len(text)
for char in text:
    ascii = ord(char)
    print(char, "\t", ascii)

Publicación traducida automáticamente

Artículo escrito por anuragrawat1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *