Puzzle T14

Color

Define a struct type, using typedef, for a color in computer graphics. Colors are a triple of red, green, and blue light intensities. Each intensity may be from 0 to 255. (But the struct definition itself can't check ranges.)

Write a function that sets the color values and another function to print a color.

/* declare the Color type */

/* function to print a Color */
void printColor( Color *c ) {...}

/* function to construct a Color */
void setColor( Color *c, int r, int g, int b ) {...}

int main()
{
  /* declare and initialize two Colors */
  Color grass, sky;
  
  setColor( &grass, 50, 200, 100 );
  setColor( &sky, 100, 100, 250 );

  /* print values */
  printColor( &grass );
  printColor( &sky );
    
  return 0;
} 


Previous Page        Answer         Next Page         Home