A29 Answer


#include <stdio.h>
#include <stdlib.h>
/* Puzzle A29 -- print a square composed of four triangles*/
const int boardsize=18 ;
int main(int argc, char *argv[])
{
  int row, col;

  /* There are two diagonals in the picture, diagA */
  /* from the top left corner and diagB from the  */
  /* the top right corner. */
  int diagA, diagB; 
  
  for ( row=0; row<boardsize; row++ )
  {
    for ( col=0; col<boardsize; col++ )
    {

      /* Column numbers for the two diagonals */
      diagA = row;
      diagB = boardsize-row-1;
      
      if ( diagA <= diagB )
      {
        if ( col >= diagA && col <= diagB )
          printf("*");
        else
          printf(".");
      }
      else 
      {
        if (  col >= diagB && col <= diagA  )
          printf("*");
        else
          printf(".");
      }
    }
    printf("\n");
  }
  
  printf("\n");
  system("PAUSE");	
  return 0;
}