How to output a pattern

Hi I want to output the following:
**********
*********
********
*******
******
*****
****
***
**
*

I have tried many thing but i couldn't get it to work. Thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
	int i, j;
	
	for(i = 10; i >= 0; i--)
	{
		for(j = 0; j <= i; j++)
		{
			cout << "*";
		}
		cout << endl;
	}
}
There are many ways to do the task. For example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>

int main()
{
   const int N = 10;

   for ( int i = N; i != 0; --i )
   {
      const char symbol = '*';
      std::cout << std::setfill( symbol ) << std::setw( i ) << symbol << std::endl;
   }

   return 0;
}



Or more advanced code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <algorithm>
#include <iterator>

int main()
{
   const int N = 10;

   for ( int i = N; i != 0; --i )
   {
      const char symbol = '*';
      std::fill_n( std::ostream_iterator<char>( std::cout, "\n" ), i, symbol );
   }

   return 0;
}
Last edited on
Topic archived. No new replies allowed.