• 0

[C++] Quick question: Printing an upside down triangle


Question

I can't seem to get this straight haha. Programming has never been my forte, and this should be pretty easy for most of you :p

I need the output to be like this:

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

It starts with one * at the bottom and increases by 2 subsequently.

Here's what I got:

#include <iostream>
using namespace std;

int main()
{
	int j=1;
	for (int i=5;i>=1;i--)
	{
		for (int k=1;k<=j;k++)
		{
			cout << " ";
		}

		for (int x=1;x<=i;x++)
		{
			cout << " *";
		}

		cout <<endl;
		j++;
		}
system("Pause");
}

It increases by 1 star rather than 2, but I can only get it centered right this way... any ideas?

Thanks!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.