Testing letters' case with if statement and logical operators - C Operator

C examples for Operator:Logic Operator

Description

Testing letters' case with if statement and logical operators

Demo Code

#include <stdio.h>

int main(void){
  char letter = 0;                               // Stores an input character

  printf("Enter an upper case letter:");         // Prompt for input
  scanf(" %c", &letter);                         // Read the input character

  if((letter >= 'A') && (letter <= 'Z'))         // Verify uppercase letter
  {/* w ww.  j a  v a  2  s  .  c  o  m*/
    letter += 'a'-'A';                           // Convert to lowercase
    printf("You entered an uppercase %c.\n", letter);
  }
  else
    printf("You did not enter an uppercase letter.\n");

  return 0;
}

Result


Related Tutorials