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
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
Is getch () necessary and what's it use ??
ReplyDeleteGetch() 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.
Deleteinstead of using this-
ReplyDeleteelse 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)
But special character range lies between 0-47, 58-64, 91-96 and 123-127. Thats why its important to use all of these..
Deleteis it necessary to use ascii values?
ReplyDeleteno it's not necessary you can use the alphabets and digits and special characters
DeleteGood
ReplyDelete#include
ReplyDelete#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();
It looks cool
Delete#include
ReplyDeleteint 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;
}
Bilkul shi hai
Deleteplz write this code inside the loop....so one can choose many characters one after another.
ReplyDeleteYou 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.
ReplyDeleteThe 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.
what can we use instead of conditionAL OPERATORS?
ReplyDeleteAwesome thnx
ReplyDeleteWhy ch variable contain
ReplyDeletegalaxy watch 3 titanium - titanium gold-arts.com
ReplyDeleteFind 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.