### Make an shape

hello i'm the beginner on programming

i need to make this shape in order :
\x\x\xx/x/x/
x\x\x\/x/x/x
xx\x\xx/x/xx
xxx\x\/x/xxx
xxxx\xx/xxxx
xxxxx\/xxxxx

with 3 input and
\x\x\x\x\xx/x/x/x/x/
x\x\x\x\x\/x/x/x/x/
xx\x\x\x\xx/x/x/x/
xxx\x\x\x\/x/x/x/
xxxx\x\x\xx/x/x/
xxxxx\x\x\/x/x/
xxxxxx\x\xx/x/
xxxxxxx\x\/x/
xxxxxxxx\xx/
xxxxxxxxx\/
with 5 input.

i already make the source code here
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````#include using namespace std; int main() { int n; cout<<"masukan nilai = "; cin>>n; for (int i=1; i<=n; i++){ for (int j=1; j<=n; j++){ if (i<=j){ cout<<"\\"; } cout<<" "; for (int w=n;w>=1;w--){ if (j==n-(w-1) && i>n-(w-1)){ cout<<" "; } } } for (int j=n; j>=1; j--){ cout<<" "; if (i<=j){ cout<<"/"; } for (int w=n;w>=1;w--){ if (j==n-(w-1) && i>n-(w-1)){ cout<<" "; } } } cout<<"\n"; for (int j=1; j<=n; j++){ cout<<" "; if (i<=j){ cout<<"\\"; } for (int w=n;w>=1;w--){ if (j==n-(w-1) && i>n-(w-1)){ cout<<" "; } } } for (int j=n; j>=1; j--){ if (i<=j){ cout<<"/"; } cout<<" "; for (int w=n;w>=1;w--){ if (j==n-(w-1) && i>n-(w-1)){ cout<<" "; } } } cout<

but is too much looping for this section how me to reduced the looping used?
Last edited on
 ``1234567891011121314151617`` ``````#include #include using namespace std; int main() { char SPACE = ' '; int N; cout << "Input N: "; cin >> N; int N2 = 2 * N; string L, R, blanks( N2, SPACE ); for ( int i = 0; i < N; i++ ) { L += "\\ "; R += " /"; } L = blanks + L; R = R + blanks; for ( int i = N2; i > 0; i-- ) cout << L.substr( i, N2 ) << R.substr( N2 - i, N2 ) << endl; }``````

or even ...

 ``123456789101112131415161718192021222324`` ``````#include #include using namespace std; string operator *( int n, string s ) { string result; if ( n <= 0 ) return ""; while ( n-- ) result += s; return result; } int main() { string B = " ", L = "\\ ", V = "\\/", R = " /"; int N; cout << "Input N: "; cin >> N; for ( int i = 0; i < 2 * N; i++ ) { int diag = N - ( i + 1 ) / 2; cout << i * B + diag * L + ( i % 2 ) * V + diag * R << '\n'; } }``````

or
 ``123456789101112131415161718192021`` ``````#include using namespace std; void diag( int i, int j, char c ) { if ( j >= i && ( j - i ) % 2 == 0 ) cout << c; else cout << ' '; } int main() { int N; cout << "Input N: "; cin >> N; for ( int i = 0; i < 2 * N; i++ ) { for ( int j = 0 ; j < 2 * N; j++ ) diag( i, j, '\\' ); for ( int j = 2 * N - 1; j >= 0 ; j-- ) diag( i, j, '/' ); cout << '\n'; } }``````

 ```Input N: 3 \ \ \ / / / \ \ \/ / / \ \ / / \ \/ / \ / \/ Input N: 5 \ \ \ \ \ / / / / / \ \ \ \ \/ / / / / \ \ \ \ / / / / \ \ \ \/ / / / \ \ \ / / / \ \ \/ / / \ \ / / \ \/ / \ / \/ ```

Last edited on
Registered users can post here. Sign in or register to post.