top of page

C Program for Traffic Light using Switch Case

Writer's picture: Rajesh SinghRajesh Singh

C Program for Traffic Light



#include <stdio.h>

#include<conio.h>

Void main ()

{

char colour;

printf ("Enter the colour of the light (R,G,Y): ");

scanf ("%c", &colour);

switch (colour)

{

case 'R':

case 'r':

printf ("STOP \n");

break;

case 'Y':

case 'y':

printf ("WAIT\n");

break;

case 'G':

case 'g':

printf ("GO \n");

break;

default:

printf ("The colour is not valid \n");

}


getch();

}



3,888 views1 comment

Recent Posts

See All

IOT Sensor MCQ

Sensor MCQ for O level Exam: Q1. Which sensor is used in Mobile phones? A.      Capacitive Touch Sensor B.      Temperature Sensor...

IOT Arduino MCQ

Building IOT Applications MCQ: Q1. Which Microcontroller is used in Arduino UNO prototyping board? A.    ATmega328m B.     ATmega328p...

1 Comment


Lakshmi sree Kesanapalli
Lakshmi sree Kesanapalli
Nov 24, 2023

Algorithm

Like
bottom of page