My friend and i were having a discussion the other day and we were having a heated argument about how to make that dang diamond pattern in C++ code...does anyone remember how to make that thing? like this?[TEX]

*
***

[/TEX]

My friend and i were having a discussion the other day and we were having a heated argument about how to make that dang diamond pattern in C++ code...does anyone remember how to make that thing? like this?[TEX]

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

[/TEX]

>My friend and i were having a discussion the other day and we were
>having a heated argument about how to make that dang diamond
>pattern in C++ code
A heated discussion, huh? Why not just write the damn thing and be done with it? There's not exactly anything to discuss. Or is this your homework and you're just trying to trick someone into giving you the code with some lame excuse of an argument with your "friend" about how to do it? :icon_rolleyes:

>does anyone remember how to make that thing?
Yes, I remember numerous ways of doing it, and I could probably come up with half a dozen new ones off the top of my head. Why don't you show us your attempt, your "friend's" attempt, and we'll tell you who's is better. That should clear up the argument quite neatly, no?

Hey this program works

#include<iostream>

using namespace std;

int main()
{
	int n = 7;					
	int m = 1;
	int x = n;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < (x - 1); j++)
			cout << " ";

		for (int k = 0; k < m; k++)
			cout << "*";

		cout << endl;
		x--;
		m = m + 2;
	}
	
	x = m - 2;
	m = 1;
	for (i = 0; i < (n - 1); i++){
		x = x - 2;
		for(int j = 0; j < m; j++)
			cout << " ";
		for(int k = 0; k < x; k++){
			cout << "*";
		}
		cout << endl;
		m++;
		
	}
	return EXIT_SUCCESS;
}

well...easiest way to do it is to make a loop that goes from number of rows and than prints number of spaces equal to (N + 1 / 2) - 1, N - number of rows, it is same as number of stars in middle row; and after that goes number of stars equal to A*2 + 1, A(number of current row)

@kameshwar - it's nice you gave the whole code but you should have given only guidelines on how to make that program...this is just an advice

that's too long

#include <stream>

main ()
{
   cout << "   *   ";
   cout << "  ***  ";
   cout << " ***** ";
   cout << "*******";
   cout << " ***** ";
   cout << "  ***  ";
   cout << "   *   ";
}

:P

How can we make a diamond pattern with using switch statement??? Any body???

@Zee Khan - Start a new thread, don't resurrect a 6 year old thread. You should try to see if you can do it first and then if it doesn't work then ask for help with the code you have.

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