The program segment given below accepts a character from the keyboard and prints the name of the corresponding color, e. g., if the user enters character R, it prints Red. However, it handles only three colors, namely, red, green and blue.
The character entered from the keyboard is first accepted in variable color (of type char) and is then tested in the switch statement. The program includes three cases corresponding to the colors red, green and blue. Note that the case values are character constants 'R’ ,‘G' and 'B' . Each case includes a printf statement to print the name of the color followed by a break statement. The output of program containing the above code is shown below.
printf("Enter character (R/G/B): ");
printf ("Red") ;