Write a program which takes a single integer input "height" and displays a "pyramid"
of this height made up of "*" characters on the screen.
Sample Output:
Pick another height (must be between 1 and 30): the triangle must be equilataural
*
***
*****
*******
*********
***********
*************

Edited 6 Years Ago by Heba91: n/a

Use 2 for loops for this.

int height=0;
for(int i=0;i<height;i++)
{
for(int j:0;j<height;j++)
{
}
}

That's a skeleton of what you need to do. It sounds like a homework assignment so fill in the blanks and it should work

Edited 6 Years Ago by bsewell: n/a

it didn't work i need an equilataural triangle and my problem is to make spaces before the stars
....*******....

Edited 6 Years Ago by Heba91: n/a

my problem is to make spaces before the stars

eg, your program needs to make a decision on whether to show a space or star.

Edited 6 Years Ago by bsewell: n/a

........*
......***
....*****
...*******
.*********
***********
*************
this is the shape what i need

How about posting your latest code, not your latest ASCII art rendition?

Then we can tell you exactly what you did wrong.

Or are you hoping that if you roll around helpless for long enough that someone will spoon-feed you the answer?

It's a choice, but it basically boils down to whether you want to learn or not. At the moment, votes favour the "no" side.

#include <iostream>

using namespace std;

int main()
{
    int x,i,n,j;
    cout<<"enter the odd number of rows :";
    cin>>x;
    for(n=x+1;n>=0;n--){
        cout<<" ";
        for (i=1;i<=x+1;i=i+2){
            for(j=i;j<=x+1;j++){
            cout<<"*";
        }cout<<endl;}}
    return 0;
}

(this is what i did but it also didn't work)

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

you went wrong in not using code tags.
You went wrong in writing C++ code when you're supposed to make a Java program.

start quote:

#include <iostream>

using namespace std;

int main()
{
    int x,i,n,j;
    cout<<"enter the odd number of rows :";
    cin>>x;
    for(n=x+1;n>=0;n--){
        cout<<" ";
        for (i=1;i<=x+1;i=i+2){
            for(j=i;j<=x+1;j++){
            cout<<"*";
        }cout<<endl;}}
    return 0;
}

(this is what i did but it also didn't work)

That is c++ code, but this is the java forum.

You seem to have omitted something very basic in programming. Have you not heard of "conditional statements"?

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.