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 3498790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:31:57+00:00 2026-05-18T12:31:57+00:00

i want to create a pattern in c++ that looks like a trianlge(or half

  • 0

i want to create a pattern in c++ that looks like a trianlge(or half a diamond)
using asteriscks: the pattern should have 1, 2, 3, 4, and end in 5 stars like this

  *
  **
 ***
 ****
*****

(but straight!)
my code is as follows:

-`#include
using namespace std;
int main()
{

int size;
cout<<"size:"<<endl;
cin>>size;

int blank=size/2;
int newsize=1;
for (int i=0; i<=size/2; i++)
{
    for(int j=blank;j>0;j--)
        cout <<" ";
    blank--;
    for(int j=newsize; j>0; j--)
        cout <<"*";
    newsize+=2;
    cout <<endl;
}


return 0;

}
`
my only problem with it is that it displays 1, 3,and 5 stars like this.

  *
 ***
*****

its just a minor problem but although i have changed different parts of the code
i dont seem to get it right.

any suggestions?

thanks
🙂

  • 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-18T12:31:58+00:00Added an answer on May 18, 2026 at 12:31 pm

    I’m not sure what you mean by "but straight", so I’ll just ignore that for now…

    Start with blank the same value as size, so that you can decrement the value each time without having to decrement by a half:

    int blank=size;
    

    Loop up to size instead of size/2 to get more lines:

    for (int i=0; i<=size; i++)
    

    Decrement by two in the loop for spaces to get half the number of spaces:

    for(int j=blank;j>0;j-=2)
    

    Increase the size by one instead of two to get the slower increase:

    newsize++;
    

    That should produce the output that you showed.

    Edit:

    I tested this to be sure, and the output is:

       *
      **
      ***
     ****
     *****
    ******
    

    To get the exact output that you asked for, start with blank one less:

    int blank=size - 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My end goal is to draw a report that looks like MS Word using
I'm trying to create a generic, reusable view, that looks like a lined notepad.
I have a hierarchy that looks something like this: class Base { public: void
I have a class that creates and uses a System.Threading.Timer, something like this: using
I want to create a pregmatch pattern which applies to: http://site.local/app/**/admin text. I created
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
i want create image animation , i have 50 images with png format now
I want to create a new field (or two) in my table that is
I have some strings, entered by users, that may look like this: ++7 7++

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.