C challenge

This is a discussion on C challenge within the C Programming forums, part of the General Programming Boards category; So i have this exercise that has me stumped . I was hoping someone here can try to do it ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    38

    C challenge

    So i have this exercise that has me stumped . I was hoping someone here can try to do it so i can learn from it

    Basiclly the program takes in a character and uses nested loops to display it like the following.

    So if you entered and 'E' it would display it like this.
    Code:
             A
           ABA
        ABCBA
      ABCDCBA
    ABCDEDCBA
    The program should be made :

    outer loop controls the rows

    3 inner loops:

    first does the spacing
    second does the ascending order
    third does the descending order

    thanks in advance

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    38
    the outcome should be in a pyramid shape. doesnt want to display it that way.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I would use an outer loop that counts the rows, and inside that big loop I'd have three smaller loops: one that just printed spaces (I need two less spaces each row), one that printed letters in order starting with 'A', and one that printed letters starting where the last one left off (this loop would be the one that printed the center letter) and went back down to 'A'.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,011
    Code:
    for each row from 0 to 'E' - 'A'
      let spaces = 'E'-'A'-row
      while spaces > 0
        print space
        --spaces
      for each letter from 'A' to 'A'+row (inclusive)
        print letter
      for each letter from 'A'+row-1 to 'A' (inclusive)
        print letter
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. AI Challenge
    By unknown_111 in forum General AI Programming
    Replies: 0
    Last Post: 10-02-2007, 12:18 AM
  2. A Challenge in C++
    By Brad0407 in forum C++ Programming
    Replies: 38
    Last Post: 07-18-2007, 12:56 PM
  3. Programming Challenge (for my school)
    By Ezerhorden in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2006, 05:56 AM
  4. Challenge?
    By Mackology101 in forum C Programming
    Replies: 5
    Last Post: 11-23-2004, 01:30 PM
  5. Requesting a challenge
    By RealityFusion in forum C++ Programming
    Replies: 8
    Last Post: 08-18-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21