+ 2

Make this program if you dare!!!!!

if the input is 5,then output should be 1 2 9 3 8 10 4 7 11 14 5 6 12 13 15 Note:1.Without Array 2.it is just a program of "Flow Of Control" i.e. it can be made only with if condition,loop,cout etc. 3.Don't simply do this: cout<<"1\n"; cout<<"2 9\n"; cout<<"3 8 10\n"; cout<<"4 7 11 14\n"; cout<<"5 6 12 13 15\n";

1st Feb 2017, 1:02 PM
Ishan Sharma
Ishan Sharma - avatar
8 Answers
+ 11
#AhriBestAnswer #MostBasic P.S. Sharma edited his original post to disqualify Ahri. I guess if I start using vectors, he'll add it to the first rule :P
1st Feb 2017, 1:28 PM
Hatsy Rei
Hatsy Rei - avatar
+ 9
print("1") print("2 9") print("3 8 10") print("4 7 11 14") print("5 6 12 13 15") #did I win?
1st Feb 2017, 1:23 PM
Ahri Fox
Ahri Fox - avatar
+ 5
C#: string s = "ABICHJDGKNEFLMO"; int x = 1, y = 0; for(int i = 0; i < s.Length; i++) { Console.Write(Convert.ToInt32(s[i])-64 + " "); y++; if(x == y) { y = 0; x++; Console.WriteLine(); } } You can run the code on my profile 👍
2nd Feb 2017, 10:40 AM
Jafca
Jafca - avatar
+ 5
@Ishan Dude, you can't keep making up rules...
2nd Feb 2017, 12:57 PM
Jafca
Jafca - avatar
+ 5
Don't know if this is the best way to do it, but I got it to work! Anyways, you can go to my profile and run this in code playground. It also works with n-sized triangles :) #include <iostream> using namespace std; int tri_sum(int val) { int sum = 0; for (int i = val; i >= 1; i--) { sum += i; } return sum; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { if (j % 2 == 0) { cout << j*n - tri_sum(j-1) - i + j << ' '; } else { cout << j*n - tri_sum(j-1) - n + i << ' '; } } cout << endl; } return 0; }
2nd Feb 2017, 11:16 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 3
@Ahri Fox 😂😂😂😂 Awesome
1st Feb 2017, 1:36 PM
Arpan Lunawat
Arpan Lunawat - avatar
+ 2
this is the final rules i am increasing the rules because i have program based on input
2nd Feb 2017, 1:00 PM
Ishan Sharma
Ishan Sharma - avatar
0
this is to be done with input i.e. if input is 5 then the above one and if input is 6 then, 1 2 11 3 10 12 4 9 13 18 5 8 14 17 19 6 7 15 16 20 21
2nd Feb 2017, 12:56 PM
Ishan Sharma
Ishan Sharma - avatar