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.

#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: ");
    scanf("%c",&c);
 Then put a condition to identify the character if lower case or upper case alphabet.

    if((c>='a' && c<='z') || (c>='A' && c<='Z'))
    {
        printf("%c is an alphabet.",c);
    }
    else
    {
        printf("%c is not an alphabet.",c);
    }
The whole code:

#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;
}
Output:


Enjoy! Happy coding!
Identify the character if alphabet or not in C Identify the character if alphabet or not in C Reviewed by code-dev on 11:06 AM Rating: 5

No comments:

Powered by Blogger.