+ 2

I want to make triangle using even number

hello, how can i make triangle using even number like this? 2 4 12 6 14 20 8 16 22 26 10 18 24 28 30

20th Nov 2017, 12:11 PM
Dermawan Adji Saputra
Dermawan Adji Saputra - avatar
5 odpowiedzi
+ 8
there is also setw and setfill from iomanip http://www.cplusplus.com/reference/iomanip/setw/
20th Nov 2017, 2:46 PM
jay
jay - avatar
+ 1
If you assume your numbers are 3 digits max, you can use printf("%4d", x); to always use 4 spaces to print the number. If you wish to do a better centering job, use the following: if (x < 10) cout<<" "<<x<<" "; // 2 spaces, x, 1 space else if (x < 100) cout<<" "<<x; // 2 spaces, x else cout<<" "<<x; // 1 space, x
20th Nov 2017, 1:52 PM
John Wells
John Wells - avatar
+ 1
rudolph, can you make the limit for the number? i want the even number less than 25 (2, 4, 6...., 24)
20th Nov 2017, 1:53 PM
Dermawan Adji Saputra
Dermawan Adji Saputra - avatar
0
thanks rudolph, you are my hero
20th Nov 2017, 1:46 PM
Dermawan Adji Saputra
Dermawan Adji Saputra - avatar
0
rudolph, can you give me the simple program again? the link is broken
21st Nov 2017, 12:34 AM
Dermawan Adji Saputra
Dermawan Adji Saputra - avatar