two triangles

hello

I'm stuck in a problem, i need to design the following shape:

nnnnnn
n n
nn
n
n
n n
n n
nnnnnnn

basicly two triangles like that

I need to be able to choose the character thats gonna get fetured (c)

ans the triangle as an height of "n"
and the its wideness is "2n-1"

all i was able to pull off was this:

n
nn
nnn
nnnn
nnnnn

could someone help me figure this out

heres my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
 
using namespace std;
 
char symbol;
const char space = ' ';

int main(int argc, char *argv[]) {
     string altura;
     stringstream ss;
     int n;
     
cout << "insira o caracter";
cin >> symbol;
    
    do {
         cout << "Insira a altura : ";
         getline(cin,altura);
         ss.clear(); ss.str(altura);
     } while ((!(ss >> n)) || (n <= 0));
 
    char *s = new char[n+1];
     memset(s,symbol,n);
     s[n] = '\0';
     for (char *p = &s[n-1]; p >= s; --p) {
         cout << setw(n) << setfill(space) << p << endl;
     }
     delete [] s;
     return 0;
 }


thanks
Last edited on
that shape is wrong
i mean this


its to triangles
one over another
Topic archived. No new replies allowed.