Tuesday, February 9, 2016

C program to print ASCII value of a given character.

#include<stdio.h>
int main()
{
char ch1;
printf("Enter any character:");
scanf("%c",&ch1);

printf("ASCII value of %c is %d ",ch1,ch1);
return 0;
}

Output of program

Enter any character:A
ASCII value of A is 65


2 comments:

  1. Replies
    1. In the statement: printf("ASCII value of %c is %d ",ch1,ch1);
      we are using two format specifiers: %c and %d; hence ch1 is written twice.

      Delete