C Program to Find ASCII Value of a Character

The program accepts a character as an input and prints its corresponding ASCII value on output screen.

The ASCII values are ranging from 0 to 128 that cover numbers from 0 to 9, uppercase letters and lowercase letters from a to z and some special characters are also the part of this system.

For example, ASCII value of 0 is 48.

C program to find ASCII value of character

or

Write a program which prints the integer equivalent of uppercase letters, lowercase letters, digits and some special symbols.

Program:

#include <stdio.h>
int main()
{
char value;
printf("Enter a Value = ");
scanf("%c", &value);
printf("integer value of %c = %d\n", value, value);
return 0;
}

Output:

In case of number

Enter a Value = 0
ASCII integer value of 0 = 48

In case of uppercase letter

Enter a Value = A
ASCII integer value of A = 65

In case of lowercase letter

Enter a Value = a
ASCII integer value of a = 97

In case of special character

Enter a Value = @
ASCII integer value of @ = 64

Explanation:

  1. Getting letter as an input from the user
  2. printing its corresponding ASCII and character values on output screen
  3. %d format specifier represents integer for printing ASCII value and %c represents character for printing the input character.

Leave a Reply