I need t o make these paterns

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

I can make only the first one, this is what I have, please help make the other ones in the same program

for (int r=1; r<=10; r++)
	{
		for (int c=1; c<=r; c++)
			cout<<"*";
		cout<<endl;
	}

Recommended Answers

All 13 Replies

they should be triangles with 1 star going to 10 and 1 reow to 10

Sorry, but you're going to have to fix the formatting of your triangles. I added code tags to preserve the spacing, but it looks like you used Daniweb's input box to format everything. The input box doesn't use a fixed width font type, so what looks good when you type it looks like crap when it's submitted. Use a text editor with a fixed width font to get your triangles right, then paste them into code tags.

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

is that better

Well, that's the same thing that you posted before. However, it's not a common variation of the "I want to make a triangle" crowd, which is why I suggested that the forum is messing up your careful formatting.

Assuming that triangles 2-4 are just reflections/rotations of the first one - all being right triangles of size 10 on the perpendicular sides, all you need are variations of the program you have.

You may have to make the inner loop decrement instead of increment. You may have to display blank spaces for some number of iterations, then stars. Look for relationships between the inner and outer loop.

triangles 2-4 are just reflections/rotations of the first one

I have 2 but can't get the other two. This is what I have.

/*	for (int r=1; r<=10; r++)
	{
		for (int c=1; c<=r; c++)
			cout<<"*";
		cout<<endl;
	}

 */
/*
	for (int r=10; r>=1; r--)
	{
		for (int c=1; c<=r; c++)
			cout<<"*";
		cout<<endl;
	}
*/	//or both do the same
	for (int r=1; r<=10; r++)
	{
		for (int c=10; c>=r; c--)
			cout<<"*";
		cout<<endl;

I changed the variables so they would run on one program
This is waht I cganged them to

for (int a=1; a<=10; a++)
	{
		for (int b=1; b<=a; b++)
			cout<<"*";
		cout<<endl;
	}
	cout<<endl;
 
	for (int c=10; c>=1; c--)
	{
		for (int d=1; d<=c; d++)
			cout<<"*";
		cout<<endl;
	}
	cout<<endl;
/*//or
	for (int e=1; e<=10; e++)
	{
		for (int f=10; f>=e; f--)
			cout<<"*";
		cout<<endl;
	}
	cout<<endl;

bbcode

my teatcher says I need to add a for loop to do the other 2, but I don't know what to do. Please help me

For the other two, the body of your inner loop will be a bit more busy. Either have another loop that prints the blank spaces, based on a relationship between the inner and outer loop variables, or use an if statement to determine if you display blanks or stars.

Also, you don't need to use different variables for each loop set. If you declare the variables before the loops, just keep reusing them.

int a, b;

for( a = 0; i < 10; a++ )
   for( b = 0; b < 10; b++ )
      //do something

for( a = 0; i < 10; a++ )
   for( b = 0; b < 10; b++ )
      //do something else

Even with the style you're using, declaring the counter variables in the loop statements, you could reuse the names a and b.

timdog i'm in the same position you are. I am able to make the first two of your traingles and after that I'm having a hard time re writing the loop.

someone in my class told me that it should look like this

for (r=10; r>=1; r--)
{
for (c=1; c<=r; c++)
		
for(int i = 0; i < 15; i++) 
cout << ' '; 
cout << '*';  
cout<<endl;
}
cout<<endl;

but that does not work, whats wrong, please help.

let the c and i loops be separate, inside the r loop.

i should come first, and be limited by the current value of r - how many blanks need to be displayed for the current line. c should pick up at the value i left off, limited by length of a row.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{   
       for (int r=1,int space=25,int s=2; r<=10; r++,space-=2,s+=2)
    {

    for (int c=1; c<=r; c++)
        cout<<"*";


    cout<<setw(space-1);


        for(int j=1;j<=r;j++)
        cout<<"*";


    cout<<setw(15);     

    for (int c=10; c>=r; c--)
        cout<<"*";

    cout<<setw(s); 

    for (int c=10; c>=r; c--)
    cout<<"*";


    cout<<endl;
    }

}
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.