elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Problema con bucles (Ayuda) en: 14 Octubre 2018, 23:03 pm
Hola buenas, bueno primero de todo perdon por las molestias pero tengo un problema con el que llevo horas comiendome la cabeza, el caso es que en mi clase nos han pedido crear un programa que represente un triangulo invertido dado un entero y una letra.
Nos ponen esto:
Write a program that, given a positive odd number x and a character c, writes the "dotted triangle" with x/2+1 rows, where each row i (0 ≤ i ≤ x/2) contains x−2*i times the character c, separated by the symbol ".". The rows will be centered. For instance, if the input is "5 k", the output must be:

k.k.k.k.k
  k.k.k
    k
and if the input is "11 #" the output must be:

#.#.#.#.#.#.#.#.#.#.#
  #.#.#.#.#.#.#.#.#
    #.#.#.#.#.#.#
      #.#.#.#.#
        #.#.#
          #
Note that there are no whitespaces to the right of the triangle.

El caso es que yo tengo un codigo ya escrito, pero no tengo idea de como generar esos espacios que hay a la izquierda del triangulo, y de quitar el punto final que tengo.
Mi codigo en cuestion es este
Código:
#include <iostream>
using namespace std;


int main () {
  int x;
  char c;
  cin >> x >> c;
  for (int i = 0; i < x / 2 + 1; ++i) {

    for (int j = 0; j / 2 != x - (2*i); ++j){

      if (j % 2 == 0) cout << c;
      else if (j % 2 != 0) cout << '.';
    }

  cout << endl;
  }
}
Y la salida que da es sin espacios a la izquierda y con un punto al final que no se quitar, espero que me puedan ayudar, se lo agredeceria muchisimo.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines