How to Write this Code?

Hey guys How to write a Code for Getting output to this pattern.
Getting Stars with this Pattern
How to write it using For loop or nested loop?

Without if else statement.

*****
-****
--***
---**
----*

I have coded this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#‎include‬ <iostream>
using namespace std;
int main()
{
	int max_row = 5;
	for (int i = 0; i < max_row; i++);
	{
		for (int j = 0; j < max_row; j++);
		{
			if (j >= i)
			{ cout << "*"; }
			else{ cout << " "; }
		}
		cout << endl;
	}
	return 0;
}
Last edited on
you copy the code wrong;

no ; at the end of line no 8
see my correct code
http://www.cplusplus.com/forum/general/155647/

you can use switch statment;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main ()
{ int max_row=5;// you can chang it value
  for(int i=0;i<max_row;i++){
        for(int j=0;j<max_row;j++){

           switch(j-i >= 0)
			{ case true:cout << "*";break;
			  case false:cout << " ";break;


			}
        }
    cout<<endl;
  }
  return 0;
}
Topic archived. No new replies allowed.