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.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;
}
}