Print Color Name - C Program

C program to read character and print color name.

i) r/R - Red
ii) g/G - Green
iii) b/B - Blue
iv) Any other - Invalid Input


Solution:

Note - In C programming, characters to be checked must be in single quotes. (' ')

#include <stdio.h>
int main()
{
     char ch;
     printf(" Enter Character : ");
     scanf("%c",&ch);
     printf("----------------------\n  ");
     if(ch=='r' || ch=='R')
     {
          printf("RED");
     }
     else if(ch=='g' || ch=='G')
     {
          printf("GREEN");
     }
     else if(ch=='b' || ch=='B')
     {
          printf("BLUE");
     }
     else
     {
          printf("Invalid Input");
     }
     return 0;
}


Output-1

color name

Output-2

color name