77.1k views
1 vote
Summary: Given integer values for red, green, and blue, subtract the gray from each value. 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). Given values for red, green, and blue, remove the gray part. Ex: If the input is: 130 50 130 the output is: 80 0 80 Find the smallest value, and then subtract it from all three values, thus removing the gray.Note: This page converts rgb values into colors.

the answer:
#include
using namespace std;
int main() {
int red;
int green;
int blue;
cin >> red >> green >> blue;
if ((red <= green) && (red <= blue)) {
cout << red;
}
else if ((green <= red) && (green <= blue)) {
cout << green;
}
else {
cout << blue;
}
return 0;
}

User Shilaghae
by
5.1k points

1 Answer

6 votes

Answer:

Follows are the code to this question:

#include<iostream>//defining header file

using namespace std;// use package

int main()//main method

{

int red,green,blue,x;//declaring integer variable

cin>> red >>green>>blue;//use input method to input value

if(red<green && red<blue)//defining if block that check red value is greater then green and blue

{

x = red;//use x variable to store red value

}

else if(green<blue)//defining else if block that check green value greater then blue

{

x= green; //use x variable to store green value

}

else//defining else block

{

x=blue;//use x variable to store blue value

}

red -= x;//subtract input integer value from x

green -=x; //subtract input integer value from x

blue -= x;//subtract input integer value from x

cout<<red<<" "<<green<<" "<<blue;//print value

return 0;

}

Output:

130 50 130

80 0 80

Step-by-step explanation:

In the given code, inside the main method, four integers "red, green, blue, and x" are 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, in the if block, it checks red variable value is greater than then "green and blue" variable. If the condition is true, it will store red variable value in "x", otherwise, it will goto else if block.

  • In this block, it checks the green variable value greater than the blue variable value. if the condition is true it will store the green variable value in x variable.
  • In the next step, else block is defined, that store blue variable value in x variable, at the last step input variable, is used that subtracts the value from x and print its value.
User Will Hayworth
by
4.5k points