Expressions and Conditional Statements (Type of Character) ID-3456

Type of Character (Id-3456)
Given a character, depending on the character write an algorithm and C program to print ‘You have entered an alphabet’ if the character entered is a letter or ‘You have entered a digit’ if the character entered is a number and ‘You have entered a special character’ otherwise.
Input Format

First line contains the character entered by the user
Output Format
Print either
You have entered an alphabet or
You have entered a digit or
You have entered a special character
sol:- C-CODE: 
#include<stdio.h>
int main()
{
    char x;
    scanf("%c",&x);
    if(x>='a'&&x<='z'||x>='A' && x<='Z'){
        printf("You have entered an alphabet");}
    else if(isdigit(x)){
    printf("You have entered a digit");}
    else{
        printf("You have entered a special character");}
}

Post a Comment

0 Comments