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.
Source code
#include <iostream>
using namespace std;
int getMin(int a, int b, int c){
if(a<b && a<c)
return a;
else if(b<a && b<c)
return b;
else
return c;
}
int main()
{
int red, green, blue;
cout<<"\nEnter red, green and blue: ";
cin>>red>>green>>blue;
int min=getMin(red,green,blue);
if(red>=min && red<=255)
red=red-min;
if(green>=min && green<=255)
green=green-min;
if(blue>=min && blue<=255)
blue=blue-min;
cout<<"\nAfter removing gray part:\n";
cout<<"Red\tGreen\tBlue\n";
cout<<red<<"\t"<<green<<"\t"<<blue;
return 0;
}
Output
Comments
Leave a comment