Identify the character if alphabet or not in C
This article is simply identifying the input character if it is a character alphabet or not, We are going to use the selection structure with the combination of logical &&, || operators and conditional operators.
First step include the header file and the main function.
Second, declare a variable with a character data type
Third, Prompt the user to enter a number
Enjoy! Happy coding!
First step include the header file and the main function.
#include <stdio.h>
int main()
{
return 0;
}
Second, declare a variable with a character data type
char c;
Third, Prompt the user to enter a number
printf("Enter a character: ");Then put a condition to identify the character if lower case or upper case alphabet.
scanf("%c",&c);
if((c>='a' && c<='z') || (c>='A' && c<='Z'))The whole code:
{
printf("%c is an alphabet.",c);
}
else
{
printf("%c is not an alphabet.",c);
}
Output:
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if((c>='a' && c<='z') || (c>='A' && c<='Z'))
{
printf("%c is an alphabet.",c);
}
else
{
printf("%c is not an alphabet.",c);
}
return 0;
}
Enjoy! Happy coding!
Identify the character if alphabet or not in C
Reviewed by code-dev
on
11:06 AM
Rating:
No comments: