# C++ code to find out if an image is B/W or color

Suppose, we are given an image that contains n pixels. The pixels can be of the following color −

• 'C' (cyan)

• 'M' (magenta)

• 'Y' (yellow)

• 'W' (white)

• 'G' (grey)

• 'B' (black)

The color of the i-th pixel is given in the string 'pixels'. Given the string, we have to find out if the given photograph is colorful or black and white. If it is a color photograph it will contain at least one pixel of color 'C', 'M' and 'Y' and we will print 'Color'; otherwise, it will contain pixels of color 'W', 'G', 'B' only and we will print 'BW'.

So, if the input is like n = 10, pixels = "GBWYM", then the output will be Color.

## Steps

To solve this, we will follow these steps −

for initialize i := 0, when i < n, update (increase i by 1), do:
if pixels[i] is not equal to 'B' and pixels[i] is not equal to 'W' and pixels[i] is not equal to 'G', then:
print("Color")
return
print("BW")

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;
#define N 100
void solve(int n, string pixels ) {
for (int i = 0 ; i < n; i++) {
if(pixels[i]!='B' && pixels[i]!='W' && pixels[i]!='G') {
cout<<"Color";
return;
}
}
cout<<"BW";
}
int main() {
int n = 10;
string pixels = "GBWYM";
solve(n, pixels);
return 0;
}

## Input

10, "GBWYM"

## Output

Color
{"ft_lang_label":"__label__en","ft_lang_prob":0.65781146,"math_prob":0.9818578,"size":3111,"snap":"2023-14-2023-23","text_gpt3_token_len":908,"char_repetition_ratio":0.17412294,"word_repetition_ratio":0.059900165,"special_character_ratio":0.32497588,"punctuation_ratio":0.08166666,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9840841,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-04-01T17:46:54Z\",\"WARC-Record-ID\":\"<urn:uuid:a608af18-a1db-4538-bd69-6ddbe8d8a39d>\",\"Content-Length\":\"38756\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4713b01f-7828-40cc-9266-cb485376da3c>\",\"WARC-Concurrent-To\":\"<urn:uuid:0a7c5d02-0b48-4acc-a577-7dbffc0ba24a>\",\"WARC-IP-Address\":\"192.229.210.176\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/cplusplus-code-to-find-out-if-an-image-is-b-w-or-color\",\"WARC-Payload-Digest\":\"sha1:ITKKEKVV3FOXGFTBXWLWTOVY7EPZTARO\",\"WARC-Block-Digest\":\"sha1:6BWK6YXDQ5CZEMC4I4E6AKU736LJIXDP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296950110.72_warc_CC-MAIN-20230401160259-20230401190259-00298.warc.gz\"}"}