202k views
0 votes
Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (In other words, equal amounts of red, green, blue yield gray).

1 Answer

4 votes

Answer:

Follows are the code to this question:

#include <iostream>//defining a header file

using namespace std; //using namespace

int main() //defining main method

{

int red,green,blue,s; //defining integer variable

cout<<"Enter value: \\ ";//print message

cin>>red>>green>>blue; //input value

if(red<green && red<blue)//defining if block that checks red value

s=red;//store red variable value to s variable

else if(green<blue)//defining else if block that checks green value less then blue

s=green;//store green variable value in s variable

else//defining else block

s=blue; //store blue variable value in s variable

//calculating red, green, blue value

red=red-s;//store red value

green=green-s;//store green value

blue=blue-s;//store blue value

cout<<red<<" "<<green<<" "<<blue;

}

Output:

Enter value:

130

50

130

80 0 80

Explanation:

In the above code, inside the Main method, four integer variable "red, green, blue, and s" is defined, in which "red, green, and blue" is used for input the value from the user end.

  • In the next step, a conditional statement is used, that checks the red variable value, if the condition is true, it will store its value in the "s" variable, otherwise, it will go to else if block.
  • In this block, the green variable checks its value less than then blue variable value, if the condition is true, it will store the green value in the "s" variable, otherwise, it will goto else block.
  • In this block, it will store the blue variable value in the "s" variable, and subtract the value of "red, green, and blue" value from "s" and store its value, and at the last, it will print its value.
User DavidAWalsh
by
5.7k points