help me!! this for beginner,,, convert

convert this to c++ language with looping 'for'

  *  
 * * 
*   *
 * *
  *   
Is the height and width a variable or fixed value? What code have you written so far as a solution to this?
In my opinion it is a too difficult assignment for a beginner.
Of course it can be done simply with using stream manipulators as for example std::setw and std::right. And I did it the way I have described. For example

1
2
3
4
5
6
7
Enter a positive number: 3

  *
 * *
*   *
 * *
  *


or

1
2
3
4
5
6
7
8
9
Enter a positive number: 4

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


But I would advice a beginner to use a character array or an object of type std::string of the fixed size and output it in a loop.
can you give me a coding?? pleasee

i have worked hard for it
Last edited on
AriWardana wrote:
i have worked hard for it

Please show the progress you have made so far (the code you wrote) and we will assist in getting it to work.
i have worked without input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream.h>

void main ()
{
int i,j,k;

for(i=1;i<=3;i++)
{
	for(j=3;j>=i;j--)
	{ cout<<" "; }

	for(k=1; k<=i; k++)
	{
		if (i==3 && k==2) {cout<<"  "; continue;}
		cout<<"* ";
	}
	cout<<endl;
}

for(i=1;i<=2;i++)
{
	for(j=1;j<=i;j++)
	{ cout<<" "; }

	for(k=2; k>=i; k--)
	{	cout<<" *"; }
	cout<<endl;
}


}


i dont know if there is an input
Last edited on
Look this thread
http://www.cplusplus.com/forum/beginner/86158/

Though the ouput is

1
2
3
4
5
6
7
   *
  ***
 *****
*******
 *****
  ***
   *


but the author uses an interesting idea that I did not even take into account early. If you will study his code you can adopt it to your task that to get the output


1
2
3
4
5
6
7
   *
  * *
 *   *
*     *
 *   *
  * *
   *
Last edited on
Topic archived. No new replies allowed.