Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C Write a program that takes a single character from the user, and tells t

ID: 3861259 • Letter: U

Question

Using C

Write a program that takes a single character from the user, and tells the user if it’s in the first half
of the alphabet (A-K) or in the second half (L-Z). It should accept both upper-case and lower-case
inputs. If the user enters any non-alphabetical character, the program should respond appropriately.
Your program should function like the below:
1> charValidator
Please enter a character: f
‘f’ is in the first half of the alphabet
2> charValidator
Please enter a character: P
‘P’ is in the second half of the alphabet
3> charValidator
Please enter a character: A
‘A’ is in the first half of the alphabet
4> charValidator
Please enter a character: $
‘$’ is not an alphabetical character

Explanation / Answer

#include <stdio.h>

int main()
{
char ch;
  
printf("Please enter a character: ");
scanf("%c", &ch);
  
if((ch >= 'a' && ch <='k') || (ch >= 'A' && ch <='K') ){
printf("'%c' is in the first half of the alphabet ", ch);
}
else if((ch >= 'l' && ch <='z') || (ch >= 'L' && ch <='Z') ){
printf("'%c' is in the second half of the alphabet ", ch);
}
else{
printf("'%c' is not an alphabetical character ", ch);
}

return 0;
}

OUtput:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Please enter a character: l                                                                                                                                                                                                                                            

'l' is in the second half of the alphabet                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Please enter a character: p                                                                                                                                                                                                                                            

'p' is in the second half of the alphabet                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Please enter a character: A                                                                                                                                                                                                                                            

'A' is in the first half of the alphabet                                                                                                                                                                                                                               

sh-4.2$ main                                                                                                                                                                                                                                                           

Please enter a character: $                                                                                                                                                                                                                                            

'$' is not an alphabetical character

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote