info@thistimebd.com

Saturday 27th of April 12:36:06am

Write a switch statement that will examine the value of a char-type variable called color and print one of the following massages, depending on the character assigned to color

Write a switch statement that will examine the value of a char-type variable

called color and print one of the following massages, depending on the character

assigned to color.

(a) RED, if either r or R is assigned to color,

(b)GREEN, if either g or G is assigned to color,

(c) BLUE, if either b or B is assigned to color,

(d) BLACK, if color is assigned any other character.


Solution:

#include

int main()

{

char color;

printf("Enter a character ");

scanf("%c",&color);

switch(color)

{

// please for charecter, use single a quotation

case r:

case R:

printf("RED");

break;

case g:

case G:

printf("GREEN");

break;

case b:

case B:

printf("BLUE");

break;

default:

printf("BLACK");

break;

}

return 0;

}