Mastery Topic 15

This program do a piramid with T, ask the user the range and print the piramid, this program use nested fors.

#include <iostream>
using namespace std;

void triangles(int a)
{
for(int i = 1; i <= a; i++)
{
cout << endl;
for(int k = i; k > 0; k–)
{
cout << «T»;
}
}
cout << endl;
for(int i = a-1; i > 0; i–)
{
for(int k = 0; k < i; k++)
{
cout << «T»;
}
cout << endl;
}}

int main()
{
int triangle;
cout << «Dame la cantidad de triángulos que quieres que aparezcan » << endl;
cin >> triangle;
triangles(triangle);
return 0;
}

Nested.PNG

Resultado de imagen para Piramide

image taken from: http://respuestas.tips/cuales-son-los-tipos-de-piramides-geometricas/

Deja un comentario