Figuras CPP

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 3

#include <iostream>

#include <conio.h>
using namespace std;
using namespace System;

int validarNum() {
int x;
do {
cout << "Ingrese un numero:";
cin >> x;
} while (x < 1 || x>10);
return x;
}

void espacios(int n) {
for (int i = 0; i < 50-(n/2); i++)
{
cout << " ";
}

void dibujarCuadradoRelleno(int n) {

for (int f = 0; f < n; f++)


{
espacios(n);
for (int j = 0; j <n; j++)
{
cout << "*";

}
cout << endl; // permite generar la imagen cuadrada
}
}
void dibujarCuadradoSinRelleno(int n) {
for (int f = 1; f <= n; f++)
{
espacios(n);
for (int c = 1; c <=n; c++)
{
if (c == 1 || c == n || f == 1 || f == n ) {
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
}

void dibujarCuadradoConLinea(int n) {
for (int f = 1; f <= n; f++)
{
espacios(n);
for (int c = 1; c <= n; c++)
{
if (c == 1 || c == n || f == 1 || f == n || c==f) {
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
}

void dibujarTrianguloSinRelleno(int n) {
for (int i = 1; i <= n; i++) {
espacios(n);
for (int j = 1; j <= i; j++) {
if (j == 1 || i == n || j == i) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
}

void dibujarTrianguloRelleno(int n) {
for (int i = 0; i <n; i++) {
espacios(n);
for (int j = 0; j < n; j++) {
if (i>=j) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
}

void main() {
int n;
n = validarNum();
dibujarCuadradoRelleno(n);
cout << endl << endl;
dibujarCuadradoSinRelleno(n);
dibujarCuadradoConLinea(n);
cout << endl;
dibujarTrianguloSinRelleno(n);
cout << endl;
dibujarTrianguloRelleno(n);
_getch();
}

También podría gustarte

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy