7.4 Character Test
7.4 Character Test
[9] is_upper - Check whether a Character is an Uppercase Letter or not.
[10] is_lower - Check whether a Character is a Lowercase Letter or not.
[11] is_alpha - Check whether a Character is an Alphabet or not.
[12] is_digit - Check whether a Character is a Digit or not.
[13] is_alphanum - Check whether a Character is an Alphanumeric Character or not.
[14] is_vowel - Check whether a Character is a Vowel or not.
1. Use if-else.
2. Use switch case.
[15] is_consonant - Check whether a Character is a Consonant or not.
[16] is_xdigit Check if the character is a hexadecimal digit.
[17] is_punct Check if the character is a punctuation character.
[18] is_equal - Test equality of two Characters.
সমাধান
[9] is_upper - Check whether a Character is an Uppercase Letter or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if(ch >= 'A' && ch <= 'Z'){
printf("Uppercase Letter\n");
}
else{
printf("Not Uppercase Letter\n");
}
return 0;
}
[10] is_lower - Check whether a Character is a Lowercase Letter or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if(ch >= 'a' && ch <= 'z'){
printf("Lowercase Letter\n");
}
else{
printf("Not Lowercase Letter\n");
}
return 0;
}
[11] is_alpha - Check whether a Character is an Alphabet or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')){
printf("Alphabet\n");
}
else{
printf("Not Alphabet\n");
}
return 0;
}
[12] is_digit - Check whether a Character is a Digit or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if(ch >= '0' && ch <= '9'){
printf("Digit\n");
}
else{
printf("Not Digit\n");
}
return 0;
}
[13] is_alphanum - Check whether a Character is an Alphanumeric Character or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')){
printf("Alphanumeric Character\n");
}
else{
printf("Not Alphanumeric Character\n");
}
return 0;
}
[14] is_vowel - Check whether a Character is a Vowel or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
printf("Vowel\n");
}
else{
printf("Not Vowel\n");
}
return 0;
}
[15] is_consonant - Check whether a Character is a Consonant or not.
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')){
if(!(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')){
printf("Consonant \n");
}
else{
printf("Not Consonant\n");
}
}
else{
printf("Not Consonant\n");
}
return 0;
}
[16] is_xdigit Check if the character is a hexadecimal digit. (function)
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')){
printf("Hexadecimal Digit\n");
}
else{
printf("Not Hexadecimal Digit\n");
}
return 0;
}
[17] is_punct Check if the character is a punctuation character. (function)
#include<stdio.h>
int main(){
char ch, lower_case;
scanf(" %c", &ch);
if(ch == '!' || ch == '"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == '-' || ch == '.' || ch == '/'|| ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '_' || ch == '`' || ch == '{' || ch == '|' || ch == '}' || ch == '~'){
printf("Punctuation Character\n");
}
else{
printf("Not Punctuation Character\n");
}
return 0;
}
[18] is_equal - Test equality of two Characters.
#include<stdio.h>
int main(){
char ch1, ch2;
scanf(" %c %c", &ch1, &ch2);
if(ch1 == ch2){
printf("Equal\n");
}
else{
printf("Not Equal\n");
}
return 0;
}
Last updated