c check if character is upper case
Certainly! Here's a C code snippet to check if a character is uppercase:
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (ch >= 'A' && ch <= 'Z') {
printf("The character is uppercase.\n");
} else {
printf("The character is not uppercase.\n");
}
return 0;
}
Explanation:
- The code begins by including the necessary header file <stdio.h>
to enable input/output operations.
- In the main()
function, a variable ch
of type char
is declared to store the input character.
- The printf()
function prompts the user to enter a character.
- scanf()
is used to take the user input and store it in the variable ch
.
- The if
statement checks whether the entered character (ch
) falls within the ASCII range of uppercase letters. The condition ch >= 'A' && ch <= 'Z'
checks if the character is between 'A' and 'Z' inclusive.
- If the condition is true, it prints that the character is uppercase; otherwise, it indicates that the character is not uppercase.