Ad

Chapter - 3: The Decision Control

In the digital world, colors are specified in Red-Green-Blue (RGB) format, with values of R, G, B varying on an integer scale from 0 to 255. In print publishing, the colors are mentioned in Cyan-Magenta-Yellow-Black (CYMK) format, with values of C, M, Y, and K varying on a real scale from 0.0 to 1.0. Write a program that converts RGB color to CMYK colors as per the following formulae: White = Max(Red/255, Green/255, Blue/255) Cyan = ((White - Green/255)/White) Magenta = ((White - Green/255)/White) Yellow = ((White - Blue/255)/White) Black = 1 - White Note that if the RGB values are all 0, then the CMY values are all 0 and the K value is 1.


Ad
G
Sections
10
Exercises
#include<stdio.h>
#include<conio.h>
int main()
{
	float r, g, b, c, m, y, k, w = 0;
	
	printf("\nEnter the color values of R, G and B : ");
	scanf("%f%f%f", &r, &g, &b);
	
	//r is replaced by r/255 and so on
	r /= 255;
	g /= 255;
	b /= 255;
	
	//Finding maximum ratio
	if(w < r)
		w = r;
	
	if(w < g)
		w = g;
	
	if(w < b)
		w = b;
	
	
	c = (w - r) / w;
	m = (w - g) / w;
	y = (w - b) / w;
	k = 1 - w;
	
	printf("\nC : %f\nM : %f\nY : %f\nK : %f", c,m,y,k);
	
	getch();
	return 0;
}
Ad

© 2024 Garbage Valuegarbage value logo