Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

C++ triangle side by side problem

$
0
0
Hello, I would like some help with this homework problem. I have to create a c++ program that will output this triangle pattern:
http://gyazo.com/124b7f7235749e8cdf0367eb29483000.png


This is my attempt:

#include <iostream>
#include <cstdlib>
using namespace std;


int main()
{

//First Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
   for (int j = 0; j < 10; j++)  //this prints stars as columns
	{
		if (j == i)
		{
			cout << "*";
		}
		else
		{
			cout << " "; 
		}
	} 
      cout << endl;  
}		

//Second triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
	for (int j = 0; j < 10; j++)  //this prints stars as columns
	{
		if (j == i)
		{
			cout << " ";
		}
		else
		{
			cout << "*";
		}
	} cout << endl;
}	


//Third Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
	for (int j = 0; j < 10; j++)  //this prints stars as columns
	{
		if (j == i)
		{
			cout << " ";
         
		}
		else
		{
			cout << "*";
		}
	} cout << endl;
	
}	



//Fourth Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
	for (int j = 0; j < 10; j++)  //this prints stars as columns
	{
		if (j == i)
		{
			cout << "*";
         
		}
		else
		{
			cout << " ";
		}
	}cout << endl;


}

}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>