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;
}
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.