Hi, i'm new to coding and i recently posted a question, but it still hasn't been resolved. I was hoping that someone can help me with the question. I really need help on creating triangles in nested while loops, Ive already made some, but there is one that I am really stuck on.
*
**
***
****
*****
******
*******
********
*********
********** \\ I have made a code for this:
int counter=1;
while (counter<=10){
int counter2=1;
while (counter2<counter){
cout<<"*";
counter2=counter2+1;
}
cout<<"*"<<"\n";
counter=counter+1;
}
I am not sure of how to do this one:
**********
--*********
----********
------*******
--------******
----------*****
------------****
--------------***
----------------**
------------------*\\ The dashes are meant to be spaces.
//Program to make asterisk pyramids
#include<iostream> /* header file for input and output */
usingnamespace std;
int main () /* allow operations from standard library */
{
int r, c, d; //initialize variables
for(r=0; r<10; r++) //loop to make the # of asterisks increase each row
{
for (c=0; c<r+1; c++) //nested for loop for asterisk period facing right
{
cout<<"*"; //print asterisk to form one side of square, pyramid
}
for (c=r; c<10; c++) //nestecd for loop for other half of square, in spaces
{
cout<<" "; //print spaces to form other half of pyramid
}
cout<<'\t'; //tab
for (c=r; c<10; c++) //loop for upside-down pyramid
{
cout<<"*"; //print pyramid
}
for (d=r+1; d>0; d--) //spaces for other half of pyramid
{
cout<<" "; //print spaces
}
cout<<'\t'; //tab
for (d=r; d>0; d--) //spaces for reverse pyramid
{
cout<<" "; //print spaces
}
for (c=r; c<10; c++) //asterisk for reverse pyramid
{
cout<<"*"; //print asterisks
}
cout<<'\t'; //tab
for (d=r; d<10; d++) //spaces for upside-down reverse pyramid
{
cout<<" "; //print spaces
}
for (c=r+1; c>0; c--) //asterisks for upside-down reverse pyramid
{
cout<<"*"; //print asterisks
}
cout<<endl; //end the line to form the pyramids
}
cout<<endl;
system ("pause"); //leaves window up
return 0; //End of main function
}
I suggest compiling this to figure out which triangles are which and going from there!