Program : Create Equilateral triangle
To make an Equilateral triangle we need total three loop two loop inside one loop. It will print Equilateral Triangle using word xx
Check Out Program for Better Understand.
#include<iostream.h>
#include<conio.h>
// Create an Equilateral Triangle
int main()
{
for(int i=1; i<=8; i++)
{
for(int sp=1; sp<=8-i; sp++)
{
cout << " ";
}
for(int j=1; j<=i; j++)
{
cout <<"xx";
}
cout <<endl;
}
/* Loop set to int i = 1 and less than or equal to 8 this means this
loop run 8 times under every time two more loop runs one that loop
give space like i wanna make xx equilateral triable like that
____xx____
___xxxx___
__xxxxxx__
_xxxxxxxx_
like this _ is space, we need to give this space i use 2nd loop
and this loop help to give spaces that here
i give first 7 space than next line 6 next 5 and so on
i set sp value to 1 and sp <=8-i initially i =1 and this imply sp value
is less than or equal to 7 at begin and this give 7 spaces and then
Now 7 spaces is given
then it proceed to next loop that is to print the xx
initally value of j =1 and its less than or equal to i and
initially i =1 and the condition is true then its run and print
xx one time
and then it give new line
and then i increment is done and same procedure done again
now in space loop it give 6 spaces
and then print xx two times
and then next line
and this procedure go on...
*/
getch();
return 0;
}
OUTPUT
To make an Equilateral triangle we need total three loop two loop inside one loop. It will print Equilateral Triangle using word xx
Check Out Program for Better Understand.
#include<iostream.h>
#include<conio.h>
// Create an Equilateral Triangle
int main()
{
for(int i=1; i<=8; i++)
{
for(int sp=1; sp<=8-i; sp++)
{
cout << " ";
}
for(int j=1; j<=i; j++)
{
cout <<"xx";
}
cout <<endl;
}
/* Loop set to int i = 1 and less than or equal to 8 this means this
loop run 8 times under every time two more loop runs one that loop
give space like i wanna make xx equilateral triable like that
____xx____
___xxxx___
__xxxxxx__
_xxxxxxxx_
like this _ is space, we need to give this space i use 2nd loop
and this loop help to give spaces that here
i give first 7 space than next line 6 next 5 and so on
i set sp value to 1 and sp <=8-i initially i =1 and this imply sp value
is less than or equal to 7 at begin and this give 7 spaces and then
Now 7 spaces is given
then it proceed to next loop that is to print the xx
initally value of j =1 and its less than or equal to i and
initially i =1 and the condition is true then its run and print
xx one time
and then it give new line
and then i increment is done and same procedure done again
now in space loop it give 6 spaces
and then print xx two times
and then next line
and this procedure go on...
*/
getch();
return 0;
}
OUTPUT
0 comments:
Post a Comment