
Piramide con asteriscos
Dev - C++
Publicado el 25 de Abril del 2019 por Administrador (718 códigos)
24.124 visualizaciones desde el 25 de Abril del 2019
Código que muestra como dibujar una piramide con asteriscos


// C++ code to demonstrate star pattern
#include <iostream>
using namespace std;
// Function to demonstrate printing pattern
void triangle(int n)
{
// number of spaces
int k = 2*n - 2;
// outer loop to handle number of rows
// n in this case
for (int i=0; i<n; i++)
{
// inner loop to handle number spaces
// values changing acc. to requirement
for (int j=0; j<k; j++)
cout <<" ";
// decrementing k after each loop
k = k - 1;
// inner loop to handle number of columns
// values changing acc. to outer loop
for (int j=0; j<=i; j++ )
{
// printing stars
cout << " *";
}
// ending line after each row
cout << endl;
}
}
// Driver Function
int main()
{
cout << "\n";
int n = 10;
triangle(n);
return 0;
}
Comentarios sobre la versión: Versión 1 (0)
No hay comentarios