I need help about nested loops

Hi m new on c++ i want this user supplies the height any one help me ? sorry my english is not good

here s picture and answer but i cant unerstand any one give me answer here picture :

http://i.hizliresim.com/ojALQ7.png
Last edited on
Here is the code with comments explaining how it works and with everything to make a working program.
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
32
33
34
35
36
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

int main()
{
    int max;
    int rows;
    int spaces;
    int r, c;
    
    cout << "Enter max stars: ";
    cin >> max;

    spaces = max;
    rows = max + max -1;
    for (r = 1; r <= rows; r++) {
	// For rows 1 through max, decrease the number of spaces.
	// The for the rest, increase the number of spaces
	if (r <= max) spaces--;
	else spaces++;

	// Print "spaces" space characters
	for (c = 1; c <= spaces; c++)
	    cout << " ";
	// Now continue printing "*" characters until you've reached max.
	for (c = spaces + 1; c <= max; c++)
	    cout << "*";

	// End the line.
	cout << endl;
    }	    
}
Last edited on
Thank you mate i already made it here s mine
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
32
33
34
35
#include <iostream>
using namespace std ;
int main() {
 int f,i,j,k,samp=1;
  cout<<(" ");
  cin>>f;
 for (i=1; i<=f; i++) 
 {
     for (k=samp; k<=f; k++) 
     {
          cout<<(" ");
     }
     for (j=0; j< i; j++) 
     {
          cout<<("*");
     }
     samp = samp + 1;
     cout<<("\n");
 }
 samp = 1;
 for (i=f-1; i>=1; i--) 
 {
     for (k=samp; k>=0; k--) 
     {
         cout<<(" ");
     }
     for (j=i; j>=1; j--)
     {
         cout<<("*");
     }
     samp = samp + 1;
     cout<<("\n");
 }
return 0;
}
Topic archived. No new replies allowed.