+ 2
I Challenge can anyone make the program below using only 2 loops and ifelse statements ..?
1 121 12321 1234321 123454321 12345654321 123454321 1234321 12321 121 1
5 Answers
+ 5
https://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()
;
}
+ 3
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/
+ 2
Great brother. I am just beginner to the c++. so I haven't thought this much. you are awesome.
+ 1
what the hell.. did i just saw +schindlabua
+ 1
it' s awesome you ask wish your future would be bright