Printing patterns

so my pattern has some issues with spaces. the pattern should be for a number between 1 and 15. the entered number is the height of the pattern.this output is for 5.
so my code prints (the s is for spaces so just ignore them)

ssss*
ss***
*****
*******
*********

while it should print
ssss*
sss***
ss*****
s*******
*********

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
int lmt=(n/2);

     int lmt1=2*lmt;

     for (int i = 0; i <n; i++)

    {

          if(i<lmt)

          {

              for (int j = 0; j < n; j++)

              {

                   if(j< lmt1)

                   {

                        cout << " ";

                   }

                   else

                   {

                        cout << "*";

                   }

              }

          }

          else

          {

              for (int j = 0; j <= 2*i; j++)

              {

                   cout << "*";

              }

          }

          lmt1=lmt1/2;

          cout << endl;

     }
Last edited on
Topic archived. No new replies allowed.