C language if condition with characters examples | set 2

Set 1:Q1-Q5      Set 2:Q6-Q10      Set 3:Q11-Q15

Question:6

WAP to take input for a character check and print whether the character is an upper case alphabet or not?(Using only single line)

Sol:

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter any character ");
    scanf("%c",&ch);
    (ch>='A' && ch<='Z')?printf("It is an upper case alphabet"):printf("It is not an upper case alphabet");

    return 0;
}

Output:

case 1:

Enter any character d
It is not an upper case alphabet

case :2

Enter any character E
It is an upper case alphabet

Question: 7

WAP to take input for a character check and print whether the character is a lower case alphabet or not?(Using only single line)

Sol:

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter any character ");
    scanf("%c",&ch);
    (ch>='a' && ch<='z')?printf("It is a lower case alphabet"):printf("It is not a lower case alphabet");

    return 0;
}

Output:

case 1:

Enter any character d
It is a lower case alphabet

case :2

Enter any character H
It is not a lower case alphabet

Question: 8

WAP to take input for a character check and print whether the character is a digit or not?(Using only single line)

Sol:

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter any character ");
    scanf("%c",&ch);
    (ch>='0' && ch<='9')?printf("It is a digit"):printf("It is not a digit");

    return 0;
}

Output:

case 1:

Enter any character 6
It is a digit

case :2

Enter any character d
It is not a digit

Question: 9

WAP to take input for a character check and print whether the character is a vowel or not?(Using only single line)

Sol:

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter any character ");
    scanf("%c",&ch);
    (ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' || ch=='o' || ch=='U' || ch=='u')?printf("It is a vowel"):printf("It is not a vowel");

    return 0;
}


Output:

case 1:

Enter any character e
It is a vowel

case :2

Enter any character w
It is not a vowel

Question: 10

Write a C program to take input for a character, check and print whether the character is an alphabet, digit or a special character?

Sol:

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter any character ");
    scanf("%c",&ch);
    if((ch>='A' && ch<='Z')|| (ch>='a' && ch<='z'))
        printf("It is an alphabet");
    else
        if(ch>='0' && ch<='9')
        printf("it is a digit");
    else
        printf("it is a special character");


    return 0;
}

Output:

case 1:

Enter any character 4
it is a digit

case 2:

Enter any character w
It is an alphabet

case 3:

Enter any character #
it is a special character

Set 1:Q1-Q5      Set 2:Q6-Q10      Set 3:Q11-Q15

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects

Number Of Visitors

0270436