
Respuesta :
Answer:
Here is the C++ program: Â
#include <iostream> Â //to use input output functions Â
using namespace std; Â //to identify objects cin cout Â
int main() { Â //start of main method Â
int red,green,blue,smallest; Â //declare variables to store integer values of red,green, blue and to store the smallest value Â
cout<<"Enter value for red: "; Â //prompts user to enter value for red Â
cin>>red; Â //reads value for red from user Â
cout<<"Enter value for green: "; Â //prompts user to enter value for green Â
cin>>green; Â //reads value for green from user Â
cout<<"Enter value for blue: "; //prompts user to enter value for blue Â
cin>>blue; Â //reads value for blue from user Â
//computes the smallest value
if(red<green && red<blue) //if red value is less than green and blue values Â
smallest=red; Â //red is the smallest so assign value of red to smallest Â
else if(green<blue) Â //if green value is less than blue value Â
smallest=green; Â //green is the smallest so assign value of green to smallest Â
else  //this means blue is the smallest Â
smallest=blue; Â //assign value of blue to smallest Â
//removes gray part by subtracting smallest from rgb Â
red=red-smallest; Â //subtract smallest from red Â
green=green-smallest; Â //subtract smallest from green Â
blue=blue-smallest; Â //subtract smallest from blue Â
cout<<"red after removing gray part: "<<red<<endl; Â //displays amount of red after removing gray Â
cout<<"green after removing gray part: "<<green<<endl; Â //displays amount of green after removing gray
cout<<"blue after removing gray part: "<<blue<<endl; Â } //displays amount of blue after removing gray Â
Explanation:
I will explain the program using an example. Â
Lets say user enter 130 as value for red, 50 for green and 130 for blue. So
red = 130 Â
green = 50 Â
blue = 130 Â
First if condition if(red<green && red<blue) Â checks if value of red is less than green and blue. Since red=130 so this condition evaluate to false and the program moves to the else if part else if(green<blue) which checks if green is less than blue. This condition evaluates to true as green=50 and blue = 130 so green is less than blue. Hence the body of this else if executes which has the statement: smallest=green; Â so the smallest it set to green value. Â
smallest = 50 Â
Now the statement: red=red-smallest; becomes: Â
red = 130 - 50 Â
red = 80 Â
the statement: green=green-smallest; Â becomes: Â
green = 50 - 50 Â
green = 0 Â
the statement: blue=blue-smallest; becomes: Â
blue = 130 - 50 Â
blue = 80 Â
So the output of the entire program is: Â
red after removing gray part: 80 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â green after removing gray part: 0 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â blue after removing gray part: 80 Â
The screenshot of the program along with its output is attached.
