Pages

Program to find ASCII value and its type of any character.

This program shows get any character and prints it's ASCII value and its type like integer, character, capital letter, special symbol. We do this by converting the character to integer and make decision on following conditions:
  • value grater than 65 and less than 90 : capital letter
  • value grater than 97 and less than 122 : small letter
  • value grater than 48 and less than 57 : integer
  • value grater than 0 and less than 47 or grater than 58 and less than 64 : special character
  • value grater than 91 and less than 96 or grater than 123 and less than 127 : special characte
Source Code:
#include <stdio.h>
#include <conio.h>

void main()
{
char ch; //store character
clrscr();
   printf("Program to get ASCII value and type of a Character! \n");
   printf("Enter any character:");
   scanf("%c", &ch);
   printf("\n");
   //convert character to integer
   int value = int(ch);
  
   if (value >= 65 && value <= 90)
    printf("ASCI value of %c is %d and is Capital Letter", ch, value);
   else if (value >= 97 && value <= 122)
    printf("ASCI value of %c is %d and is Small Letter", ch, value);
   else if (value >=48 && value <= 57)
    printf("ASCI value of %c is %d and is Integer", ch, value);
   else if ((value >= 0 && value <= 47) || (value >= 58 && value <= 64))
    printf("ASCI value of %c is %d is Special Character", ch, value);
   else if ((value >= 91 && value <= 96) || (value >= 123 && value <= 127))
    printf("ASCI value of %c is %d is Special Character", ch, value);
   else
    printf("Enter Characeter only");

   getch();
}

Output:
Program to get ASCII value and type of a character!
Enter any Character : A
ASCII value of A is 65 and is Capital Letter.


@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment