Identifying a compressed gas cylinder is
based on the first letter of the
cylinder’s color printed on the cylinder. For Example
‘Y’ or ‘y’ for yellow, ’O’
or ‘o’ for orange and so on. Cylinder colors and associated contents are as
follows.
Orange
--
Ammonia
Brown
--
Carbon monoxide
Yellow
--
Hydrogen
Green
--
Oxygen.
Write a C program using switch case to identify the type of gas compresse
d
in a given cylinder.
#include <stdio.h>
int main() {
char ch;
char* gas;
printf("Enter a gas cylinder's color: ");
scanf("%c", &ch);
switch (ch) {
case 'o':
case 'O':
gas = "Ammonia";
break;
case 'b':
case 'B':
gas = "Carbon monoxide";
break;
case 'y':
case 'Y':
gas = "Hydrogen";
break;
case 'g':
case 'G':
gas = "Oxygen";
break;
default:
gas = "Unknown";
}
printf("There is %s in a given cylinder\n", gas);
return 0;
}
Comments
Leave a comment