+ 4

How should I generate this shape? 1 1 2 1 2 3 1 2 1

I want to build a program to show this output: 1 1 2 1 2 3 1 2 1 what should I do? I mean : << what is the source code of this program? >>

21st Jan 2017, 4:49 PM
Navid Kouhro
Navid Kouhro - avatar
7 odpowiedzi
+ 3
you can see it in my codes for c++
21st Jan 2017, 7:38 PM
ymoon
+ 5
for(int i=1;i <=3;i++) { for(int k=1;k<=i;k++) { printf ("%d ",k); } printf ("\n"); } for(int i=2;i >=1;i--) { for(int k=1;k<=i;k++) { printf ("%d ",k); } printf ("\n"); }
5th Feb 2017, 1:02 AM
Umamaheswararao Tumma
Umamaheswararao Tumma - avatar
+ 3
In Python you can do this. Try copying the logic to your language of choice. n = "3" s = "1" lines = [] for i in range(2, n + 2, 2): lines.append("{:^{n}}".format(s, n=n)) s += "{i}{j}".format(i=i, j=i + 1) lines += reversed(lines[:-1]) for l in lines: print(l)
21st Jan 2017, 7:16 PM
Paul
Paul - avatar
+ 2
navid do you now know the answer
21st Jan 2017, 6:42 PM
RanjOyHunTer
RanjOyHunTer - avatar
+ 2
Thank you all !
22nd Jan 2017, 6:10 PM
Navid Kouhro
Navid Kouhro - avatar
+ 1
yes use loops
21st Jan 2017, 4:58 PM
Tenny Brown
Tenny Brown - avatar
+ 1
good
28th Jan 2017, 2:49 AM
Abdul Sami Ayoubi
Abdul Sami Ayoubi - avatar