elow I'm trying to create a program that will display the output :

*
 **
   ***
     ****

please help me

int main()
{
   for(int i=0;i<=7;i++)
       {for(int j=0;j<=i;j++)
         cout<<'*';
         for(nt k=0;k<=i;k++)  
            cout<<' ';

then what next

its only give the output

*
 **

please help me ! ! ! thanks

you probably need to add more braces, like this, and don't put braces on the same line as other code because it makes the program moe difficult to read and understand. Strive for clarity, not cuitness.

int main()
{
   for(int i=0;i<=7;i++)
   {
        for(int j=0;j<=i;j++)
        {
            cout<<'*';
            for(int k=0;k<=i;k++)  
            {
                   cout<<' ';
             }
        }
    }
int main()
{
   for(int i=0;i<=7;i++)
   {
        for(int j=0;j<=i;j++)
        {
            cout<<'*';
            for(int k=0;k<=i;k++)  
            {
                   cout<<' ';
             }
        }
    }
}

The output of that program looks rather interesting (especially if you add a newline at the end of the outer loop, this looks the best, trust me!), but I don't quite think it's what the OP wanted. ;-)

The thing is that the spaces have to be printed out before the stars. 2 separate loops should be used to achieve this, and they should not be nested. This is what I came up with:

for(int i=0;i<=7;i++)
   {
        // just print out the spaces
        for(int j=0;j<=i;j++)
        {
            cout<<' ';
        }
        // rinse and repeat with the *s
        for (int j=0; j<=i; j++)
        {
            cout << '*';
        }
        // don't forget the newline
        cout << endl;
    }

thanks for the reply its work so you should first cout the space before the asterisk

wow thanks a lot,can i ask ,if you can also use the iomanip.h? for setw?

>so you should first cout the space before the asterisk
Yes.

>if you can also use the iomanip.h?
Use iomanip instead, it's part of the standard C++.

>for setw?
Yes, that's another way of doing it. You could replace the first loop with a call to setw , passing i+1 as the parameter.

What is the progrsm used in c++?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.