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

  • Home
  • SEARCH
  • 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 6173091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:30:27+00:00 2026-05-23T23:30:27+00:00

i want to write a shape with * and | the shape is below.

  • 0

i want to write a shape with ” * ” and ” | ” the shape is below.
The program must take height and width from user.Width is column number without ‘ | ‘.I tried to write but confused.My code sometimes works great and sometimes being stupid.For example when i enter height : 13, width : 4 it writes one more,if witdh is 1 it enters infinite loop.While trying to solve it became too conflicted.Must i fix it or rewrite ? Here is the code : height =10, width = 5

|*____|    
|_*___|
|__*__|
|___*_|
|____*|
|___*_|
|__*__|
|_*___|
|*____|
|_*___|
      private static void Function()
      {
        int height, width;

        if (width == 2)
            while (height > 0)
            {
                FirstPart(width, height);
                height -= width;
            }
        else
            while (height > 0)
            {
                if (height > 1)
                {
                    FirstPart(width, height);
                    height -= width;
                }
                if (height > 0)
                {
                    SecondPart(width, height);
                    height -= width - 2;
                }
            }
    }


    private static void FirstPart(int width,int height)
    {

        if(height > width)
             for (int i = 0; i < width; i++)
             {
                for (int j = 0; j < width+2; j++)
                {

                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                         if (i + 1 == j)
                            Console.Write("*");
                         else
                             Console.Write(" ");
                }
             Console.WriteLine();
        }
        else
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width + 2; j++)
                {

                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                        if (i + 1 == j)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                }
                Console.WriteLine();
            }
    }
    private static void SecondPart(int width,int height)
    {

        if(height > width)

            for (int i = 0; i < width-2; i++)
            {
               for (int j = 0; j < width+2; j++)
               {

                if (j == 0 || j == width + 1)
                    Console.Write("|");
                else
                    if (i + j == width-1)
                        Console.Write("*");
                    else
                        Console.Write(" ");
            }
            Console.WriteLine();
        }
        else
            for (int i = 0; i < height; i++)
            {                                     
                for (int j = 0; j < width + 2; j++)
                {
                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                        if (i + j == width - 1)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                }
                Console.WriteLine();
            }
    }            
  • 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-05-23T23:30:27+00:00Added an answer on May 23, 2026 at 11:30 pm
        private static void WriteStars(int width, int height)
        {
            int j = 0;
            for (int i = 0; i < height; i++)
            {
                Console.Write("|");
                for (int f = 0; f < width; f++)
                {
                    if (f == Math.Abs(j))
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                j++;
                if (Math.Abs(j) == width - 1)
                {
                    j *= -1;
                }
                Console.WriteLine("|");
            }
        }
    

    Probably going to get downvoted for giving you a complete answer, but maybe it’ll show you one correct approach and you can learn something from it…

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

Sidebar

Related Questions

I want to write a program in which I must recognize whether shapes collide
Within a VB.NET program, I want to read files from a filesystem, then write
I want to create a single shape file from multiple mxd's that have multiple
Hello I want write my own desktop sharing application in Java. The application should
I want to write a Swing application in Griffon but I am not sure
I want to write a command that specifies the word under the cursor in
I want to write a little DBQuery function in perl so I can have
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
I want to write a word addin that does some computations and updates some

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.