02/03/2015

C++ program to print ASCII value of a character

Problem:- Write A Program To Find ASCII Value Of Any Character or C++ program to print ASCII value of a character or C program to print ASCII value of a character

ASCII:- Abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they support many additional characters. 

ASCII-code order is also called ASCIIbetical order.The main deviations in ASCII order are:

1. All upper case come before lowercase letters; for example, "Z" precedes "a".

2. Digits and many punctuation marks come before letters.

ASCII Value Chart Is Below 

ASCII Value Chart

source-Wikipedia

Logic:- As we know that  every key in keyboard has a unique ASCII key, so for as you enter or press any key on keyboard we take string and convert string into integer value, or we can also take a string and print the string ASCII value using loop as you see in the below program. In this program, i am taking a character or string and by using loop convert the string into integer, actually string in not converting it just printing an integer value of that character and the loop is running until our string not finished that's why we use '\0' means end of string or we can say that last character in string.

Example:-

 for(i=0; str[i]!='\0'; i++)
 {
 ch=str[i];
 cout<<(int)ch<<" ";
 }

as you can see that each character of the string array is storing in character and print the character ASCII value.

Explanation:-  ASCII Full Form " American Standard Code for Information Interchange ". Every Character of your Keyboard Have It's Own Unique Number Like 

ASCII value for small character ' a ' to ' z ' is ' 97 ' to ' 122 '.
ASCII value for capital character ' A ' to ' Z ' is ' 65 ' to ' 90 '.
ASCII value for number ' 0 ' to ' 1 ' is ' 48 ' to ' 57 '  etc.

Solution:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
 string str;
 int i;
 char ch;

 cout<<"Enter String Or Character For ASCII Value \n";
 cin>>str;

 cout<<"\nString Is Given Below\n";
 cout<<str; 

 cout<<"\n\nASCII Value Of Given String Or Character Is Below\n\n";

 for(i=0; str[i]!='\0'; i++)
 {
 ch=str[i];
 cout<<(int)ch<<" ";
 }

 cout<<endl;
  return 0;

}

Output:-

C++ program to print ASCII value of a character


You May Like This:-

1. C++ Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol

2. Java Program To Find Area Of Triangle

3. C++ Program For Calculate Simple Interest

4. C++ Program For Find The Gross Salary Of An Employee

5. C++ Program For Calculate Percentage Of 5 Subjects

6. Java Program For Converting Temperature Celsius Into Fahrenheit

7. C Program To Find Character Is Vowel Or Not

8. Hacker Rank Solution Program In C++ For " StringStream "

9. Hacker Rank Solution Program In C++ For " Attribute Parser "

10. Geeksforgeeks Solution For " Reverse Coding "


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: