C language if condition with characters examples | set 2

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

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

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

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

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

Important Pages