5 Answers
New Answer1 121 12321 1234321 123454321 12345654321 123454321 1234321 12321 121 1
10/17/2016 5:32:41 PM
Zoetic_Zeel5 Answers
New Answerhttps://code.sololearn.com/cOaI43CDN1WV/#cpp Two for loops and one if-else :) I had to add a bit of space around the diamond so the Code Playground doesn't mess up the output. #include <cstdio> #include <cstdlib> #define P(c) putchar(c) #define A(x) abs(x) #define F(i) for(int i=-8;i<=8;i++) #define R(x) return 0; int main() { F (i) {F(j) {int a= A(i)+A(j); if(a>5)P(32) ;else P(54 -a);} P( 10);} R() ; }
Came up with my own solution as well: #include <iostream> #include <cmath> using namespace std; int main() { int x, i, j, m = 5; // m = Max for(i = -m; i <= m; i++) { x = 0; for(j = m; j >= -m; j--) cout << (abs(i)<=m-abs(j) ? (j<0?--x:++x) : 0); cout << "\n"; } return 0; } http://www.sololearn.com/app/cplusplus/playground/cvYHBj7gXPaG/
Great brother. I am just beginner to the c++. so I haven't thought this much. you are awesome.
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message