Google Add

Search

Program to Print ASCII value of Input Character - C, C++ Code

Write a C, C++ program to print a ASCII value of input character. In this program, A character is entered by a user and our code prints it's ASCII value.

What is ASCII Value ?

In C, C++ programming, Every character is given an integer value to represent it. This integer value is known as ASCII code or value.

Check some programming questions solved with the help of ASCII code.

Program to print ASCII value in C, C++

Program to convert string from uppercase to lowercase

Programming questions on strings

C, C++ Programming MCQ


Logic to Print ASCII value of Input Character

1. Take character as input from user.

2. Print the character using (%d modifier). It will print it's ASCII value.


Program to Print ASCII value of Input Character in C


#include <stdio.h>

main()
{
   char ch;
   
   printf("Input character to print it's ASCII value \n");
   scanf("%c",&ch);
   
   printf("ASCII value of a input character is \n");
   printf("%d",ch);
}

Program to Print ASCII value of Input Character in C++

#include <iostream>
using namespace std;

int main() {
 
 char ch;
 int val;
 
 cout << "Input any character to print it's ASCII value \n";
 cin >> ch;
 
 /* Assign it's ASCII value */

 val = ch;
 
 cout << "\n ASCII value of a input character is \n" << val;
 
 return 0;
}

Output :

Input any character to print it's ASCII value : R

ASCII value of input character is :  82


Sorting Algorithm and it's time complexity

Basic programs for practice

No comments:

Post a Comment