Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

6/28/2023 https://skillrack.com/faces/candidate/labcodeprograms.

xhtml

MITHUN MOORTHY V-2212017@nec  0/10  18 0 0  621  5557

 Valid Till: 31-May-2026

 Home  Reports  Profile  Help  Logout

Go Back

Completed Programs

Traffic Light Controller (Id-12879)

The program must accept a character CH representing the color of traffic lights. The
program must print the output based on the following conditions.
- If CH is r or R, then the program must print the string value "RED - STOP".
- If CH is y or Y, then the program must print the string value "YELLOW - WAIT".
- If CH is g or G, then the program must print the string value "GREEN - GO".
- For any other values of CH, the program must print the string value "INVALID".

Example Input/Output 1:
Input:
r

Output:
RED - STOP

Example Input/Output 2:
Input:
Y

Output:
YELLOW - WAIT

Example Input/Output 3:
Input:
o

https://skillrack.com/faces/candidate/labcodeprograms.xhtml 1/2
6/28/2023 https://skillrack.com/faces/candidate/labcodeprograms.xhtml

Output:
INVALID
Show My Solution

2212017@nec 26-Apr-2023 11:40:17 MITHUN MOORTHY V 2212017 CSE

#include<stdio.h>
#include<stdlib.h>

int main()
{
char s;
scanf("%c",&s);
s=toupper(s);
switch(s){
case 'R':
printf("RED - STOP");
break;
case 'Y':
printf("YELLOW - WAIT");
break;
case 'G':
printf("GREEN - GO");
break;
default:
printf("INVALID");
break;
}
}

https://skillrack.com/faces/candidate/labcodeprograms.xhtml 2/2

You might also like