Write a c program to display rainbow color using switch statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int colorcode;
clrscr();
printf("Enter the color code: ");
scanf("%d",&colorcode);
switch(colorcode)
{
case 1: printf("VIOLET");
break;
case 2: printf("INDIGO");
break;
case 3: printf("BLUE");
break;
case 4: printf("GREEN");
break;
case 5: printf("YELLOW");
break;
case 6: printf("ORANGE");
break;
case 7: printf("RED");
break;
default: printf("Error in color code");
}
getch();
}
Output:
run 1:
Enter the color code: 6
ORANGE
run 2:
Enter the color code: 9
Error in color code
No comments: