Answer to Question #265126 in C++ for acky_1

Question #265126

The information about colours is to be stored in bits of a variable called colour. The bit

number 0 to 7, each represent 8 colours of a rainbow, i.e. bit 1 represents Blue, 2 represents Green,

and so on (see table below). Write a C++ program that asks the user to enter a number and based on

this number, an eight lined rainbow (of asterisks *) is to be displayed, such that, if the bit is ON,

respective colour is displayed otherwise black line is drawn (not visible).


1
Expert's answer
2021-11-12T17:32:55-0500
#include<stdio.h>
#include<conio.h>
int main() {


    char color;
    int n;
    printf("Enter a number between 1 and 7: ");
    scanf("%d",&n);
    switch(n){
        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("Invalid Input");
    }
    
    return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS