Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:17:02+00:00 2026-06-17T22:17:02+00:00

I need to create a right triangle starting on the right working left. Ex.

  • 0

I need to create a right triangle starting on the right working left.
Ex. (–’s are spaces)

––––X
–––XX
––XXX
–XXXX
XXXXX

A number (and the character; ex X) will be give before hand in runner. Which the code I was given. I need code to make triangle. For example if the number was 5 each line would add up to 5 characters counting from one X with 4 spaces. Then there would be 5 rows last would be all X’s.

Update:
My code prints out

––––X
–––X
––X
–X
X
(–’s spaces, no spaces after character)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:17:03+00:00Added an answer on June 17, 2026 at 10:17 pm

    Okay, let’s start with the number 5. The best bet is to simply think about what has to be output on each line and then loop over the lines doing that.

    With that number, you have to output 5 lines as follows (I’ll use . for spaces since it’s easier to discern adjacent ones):

    ....X
    ...XX
    ..XXX
    .XXXX
    XXXXX
    

    Look at each line as follows:

    • The first line has 4 spaces and an x.
    • The second line has 3 spaces and 2 x‘s.
    • The third line has 2 spaces and 3 x‘s.
    • The fourth line has 1 spaces and 4 x‘s.
    • The fifth line has no spaces and 5 x‘s.

    I sense a pattern here ((4,1), (3,2), (2,3), (1,4), (0,5)) – the first number starts at n-1 (4 in this case) and decreases to 0. The second number starts at 1 and increases to n (5 in this case).

    In pseudo-code (which is all you get from me for homeworky-type questions), it looks something like:

    def maketriangle (n):
        for lineidx = 1 to n:
            for charidx = 1 to n - lineidx:   // 4 3 2 1 0
                output " "
            for charidx = 1 to lineidx:       // 1 2 3 4 5
                output "X"
            output newline
    

    Your job is to then convert that into real code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create some unit test of my code that are working right
I need to create a one-lined 3-column layout. The left and right columns should
I'm in a mobile programming course right now and we need to create a
Need to create a custom DNS name server using C which will check against
I need to create several custom event classes for a Qt application. Right now,
I need to create a layout with a list of checkboxes on the left
I need to use CSS triangle to create and arrow. This is the one
I need to create a button where there is a icon in the left
I need to create a custom push button which will have 3 different background
I need to create a list in a grid style, so there will be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.