+ 2

[Challenge] How will you print the following pattern in c++?

1 2 5 3 6 8 4 7 9 10 There must be a good logic in your code and it should be as short as possible.

19th Jan 2018, 6:35 PM
Dev Dutt
Dev Dutt - avatar
6 Answers
+ 21
for(int a=1;a<=n;a++) for(int b=1,d=a;b<=a;d+=n-b,b++) System.out.print(d+(b!=a?" ":"\n")); //works for general â˜ș
19th Jan 2018, 8:28 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
https://code.sololearn.com/cytSurrOBD4M/?ref=app
19th Jan 2018, 9:21 PM
UraL
+ 3
https://code.sololearn.com/cZP831clM5Xb/?ref=app
19th Jan 2018, 8:24 PM
UraL
+ 3
I think identical with @ Swapnil More. I don't peep;-)
19th Jan 2018, 8:26 PM
UraL