click on this link......

LinkGrand.com

Tuesday 10 September 2013

To find whether character entered is capital letter, small case letter,a digit or a special symbol

Any character is entered through the keyboard, write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.

Characters                     ASCII VAlues
A-Z                                65-90
a-z                                  97-122
0-9                                 48-57
Special symbols               0-47, 58-64, 91-96, 123-127

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter a character:");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
{
printf("\n Upper case letter");
}
else if(ch>=97 && ch<=122)
{
printf("\n Lower case letter");
}
else if(ch>=48 && ch<=57)
{
printf("\n Digit");
}
else if((ch>=0 && ch<=47) || (ch>=58&& ch<=64) || (ch>=91 && ch<=96) || (ch>=123 && ch<=127))
{
printf("\n Special symbol");
}
getch();
}

Output1:

Enter a Character: H
Upper case letter

Output2:

Enter a Character: g
Lower case letter

Output3:

Enter a Character: 8
Digit

Output4:

Enter a Character: @
Special symbol


17 comments:

  1. Is getch () necessary and what's it use ??

    ReplyDelete
    Replies
    1. Getch() is used for console output. It is necessary to hold the output screen. You can see it by commenting it to better understand the concept.

      Delete
  2. instead of using this-
    else if((ch>=0 && ch<=47) || (ch>=58&& ch<=64) || (ch>=91 && ch<=96) || (ch>=123 && ch<=127))
    u can simply use this
    else if(ch>=0 && ch<=127)

    ReplyDelete
    Replies
    1. But special character range lies between 0-47, 58-64, 91-96 and 123-127. Thats why its important to use all of these..

      Delete
  3. is it necessary to use ascii values?

    ReplyDelete
    Replies
    1. no it's not necessary you can use the alphabets and digits and special characters

      Delete
  4. #include
    #include
    void main()
    {
    char ch;
    printf("enter the character:");
    scanf("%c",&ch);
    if(ch>127)
    {
    printf("invalid entry");
    }

    elseif(ch>=65&&ch<=90)
    {
    printf("capital");
    }

    elseif(ch>=97&&ch<=122)
    {
    printf("character is small");
    }
    elseif(ch>=48&&ch<=57)
    {
    printf("digit");
    }
    else
    {
    printf("special symbol");
    }
    getch();

    ReplyDelete
  5. #include
    int main()
    {
    char ch;
    scanf("%ch", &ch);
    if(ch>'A' && ch<'Z')
    printf("You entered capital letter!");
    else if(ch>='a' || ch<='z')
    printf("You entered small letter!");
    else
    printf("You entered invalid character!");

    return 0;
    }

    ReplyDelete
  6. plz write this code inside the loop....so one can choose many characters one after another.

    ReplyDelete
  7. You found an exciting summer job for five weeks. It pays, say, $15.50 per hour. Suppose that the total tax you pay on your summer job income is 14%. After paying the taxes, you spend 10% of your net income to buy new clothes and other accessories for the next school year and 1% to buy school supplies. After buying clothes and school supplies, you use 25% of the remaining money to buy savings bonds. For each dollar you spend to buy savings bonds, your parents spend $0.50 to buy additional savings bonds for you. Write a program that prompts the user to enter the pay rate for an hour and the number of hours you worked each week.
    The program then outputs the following:
    a. Your income before and after taxes from your summer job. b. The money you spend on clothes and other accessories. c. The money you spend on school supplies. d. The money you spend to buy savings bonds. e. The money your parents spend to buy additional savings bonds for you.

    ReplyDelete
  8. what can we use instead of conditionAL OPERATORS?

    ReplyDelete
  9. galaxy watch 3 titanium - titanium gold-arts.com
    Find titanium jewelry piercing contact information titanium necklace mens for the latest galaxy watch 3 titanium tent stove titanium titanium bar stock - titanium gold-arts.com with titanium easy flux 125 amp welder the contact number below.

    ReplyDelete