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<stdio.h>
int main()
{
char color;
printf("Enter a character ");
scanf("%c",&color);
switch(color)
{
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;
}
0 comments:
Post a Comment