(a)        (b)               (c)             (d)
 *             **********        **********               *
 **            *********          *********              **
 ***           ********            ********             ***
 ****          *******              *******            ****
 *****         ******                ******           *****
 ******        *****                  *****          ******
 *******       ****                    ****         *******
 ********      ***                      ***        ********
 *********     **                        **       *********
 **********    *                          *      **********

I managed to do a and b, but I am stuck with c and d..Can someone help me, just perhaps describe the logic.. I will try it out myself.

#include<iostream.h>
#include<conio.h>
    using namespace std;

    int main()
    {

        clrscr();
        int i,j;
        cout<<"(a)";
        cout<<"\n";
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=i;j++)
            {
                cout<<"*";

            }
            cout<<"\n";
        }

        cout<<"\n";
        cout<<"(b)";
        cout<<"\n";
        for(i=10;i>0;i--)
        {
            for(j=i;j>0;j--)
            {
                cout<<"*";

            }
            cout<<"\n";
        }

        cout<<"\n";
        cout<<"(c)";
        cout<<"\n";
        for(i=1;i<=10;i++)
        {
            cout<<" ";
            for(i=2;i<=10;i++)
            {
                cout<<"*";
            }




        }
        return 0;
    }

Edited 4 Years Ago by Manojpandey96

#include<iostream.h>
#include<conio.h>
using namespace std;

int main()
{
int i,j,k,l;
cout<<"(a)";
cout<<"\n";
for(i=1;i<=10;i++)
{
    for(j=1;j<=i;j++)
    {
        cout<<"*";
    }
    cout<<"\n");
}
cout<<"\n";
cout<<"(b)";
cout<<"\n";
    for(i=10;i>0;i--)
    {
    for(j=i;j>0;j--)
    {
        cout<<"*";
    }
    cout<<"\n";
}
cout<<"\n";
cout<<"(c)";
cout<<"\n";
int b=10,s=0;
for(i=1;i<=10;i++)
{
    for(k=1;k<=s;k++)
            {
        cout<<" ";
    }
    for(l=1;l<=b;l++)
    {
        cout<<"*";
        }
    cout<<"\n";
    b=b-1;
    s=s+1;
}
cout<<"(d)";
cout<<"\n";
b=1;
s=9;
for(i=1;i<=10;i++)
{
    for(k=1;k<=s;k++
            {
        cout<<" ";
    }
    for(l=1;l<=b;l++)
    {
        cout<<"*";
        }
    cout<<"\n";
    b=b+1;
    s=s-1;
}
return 0;
}

in this code s is used for spaces & b is used for triangle pattern to form
if you use 10 or any integer there it will not work & will give you a rectangle
since it will repeat again for coming inside loop

I don't know if this code works
since i wrote it using java
plz check if any errors were there
i tried to completely rewrite in c++.
I dont know that too much but still can help you with this

hope i helped you solving your problem

Comments
Hope you get a good grade doing his homework for him. Thanks for helping make this the Lazy Student's Dream Site.

Congratulations on having working code for solutions (a) and (b).

If you take a look at what's happening with (c) you'll probably realise that for each line printed the number of spaces is incremented and the number of asterisks decremented. In (d) it's the opposite: for each line the number of spaces is decremented and the number of asterisks incremented.

If you write down the number of spaces and the number of asterisks in each line, you should be able to figure out what to do within the loop.

Try to make a simple relation between the number of lines and number of spaces / and number of asterisks.

If you can't explicitly make a relation, use separate variables that controls asterisks to be printed in a specific line number, spaces to be printed in a specific line number.

you can visit this site for your needed solution <URL SNIPPED>

Edited 4 Years Ago by peter_budo: No seflpromotion

Just as a warning to others, I followed the link in niravn's post, and something malicious occurred. My advice, don't follow the link.

ETA: it looks as though niravn is particularly keen to drive people to external links, judging from previous posts.

Edited 4 Years Ago by Bob

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