Puzzle L38


Print a shaggy centered truncated triangle

[M-10]As above, write a function that prints a centered triangle with a base of N characters and a top row of T characters. But now, use a different character for the first half of each line, the center, and the last half of each line.

          ///|\\\
         ////|\\\\
        /////|\\\\\
       //////|\\\\\\
      ///////|\\\\\\\
     ////////|\\\\\\\\

Each row of the triangle has an odd number of characters. You will have to modify center().

#include <stdio.h>

void center(char left, char cent, char right, int count, int length)
{
}

void shaggyTruncTriangle(char left, char cent, char right, int base, int top, int length)
{
}

int main()
{
  shaggyTruncTriangle('/', '|', '\\', 17, 7, 27);   
  return 0;
}

The character constant '\\' in the above means just a single backslash. Since backslash is used as an escape character, two in a row are needed to ask for just one.



Previous Page        Answer         Next Page         Home