WAP to display the ASCII value of a given character

WAP to display the ASCII value of a given character

 

Uppercase A has ASCII value 65 in decimal .So for Z ,the value is 90 in decimal.

Lowercase a has ASCII value 97 in decimal .So for z ,the value is 122 in decimal.

Write a program to display the ASCII value of a given character

#include<stdio.h>
#include<conio.h>

int main() {
  char ch;
  printf("Enter any character:\n");
  scanf("%c",&ch);
  printf("ASCII value of %c is %d",ch,ch);
  getch();
  return 0;
}

When we declare a variable as a character(char) then that variable can have both character and the ASCII value of that character. So while printing, if we use %c then it will print the character but if we use %d then it will print its ASCII value.

Output

Given input is A, and ASCII value is 65

ASCII valuse of A

Also, see the program made from printf() function

Share this post