ADVERTISEMENT
ADVERTISEMENT

Ruby program to print ASCII value of given character

Ruby Example: Write a program to print ASCII value of given character.
Submitted by Nidhi, on December 12, 2021

Problem Solution:

In this program, we will create some character variables and print the corresponding ASCII values using the ord() function.

Program/Source Code:

The source code to print the ASCII value of a given character is given below. The given program is compiled and executed successfully.

# Ruby program to print ASCII value 
# of given character

ch1 = 'A';
ch2 = 'C';
ch3 = 'a';
ch4 = 'd';

print "ASCII value of 'ch1' is: ",ch1.ord(),"\n";
print "ASCII value of 'ch2' is: ",ch2.ord(),"\n";
print "ASCII value of 'ch3' is: ",ch3.ord(),"\n";
print "ASCII value of 'ch4' is: ",ch4.ord(),"\n";

Output:

ASCII value of 'ch1' is: 65
ASCII value of 'ch2' is: 67
ASCII value of 'ch3' is: 97
ASCII value of 'ch4' is: 100

Explanation:

In the above program, we created 4 variables ch1, ch2, ch3, ch4 initialized with 'A', 'C', 'a', 'D' respectively. Then we got the ASCII value of characters using the ord() function and printed the result.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.