Need help with loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need help with loops

I need a algorithm making that pyramid: 1 12 123 1234 12345 ...........

5th Jan 2017, 10:06 PM
LordaBG
4 Answers
+ 2
In C#... string s = ""; for(int i = 1; i < 6; i++) { s += i.ToString(); Console.WriteLine(s); }
6th Jan 2017, 1:33 AM
Laurence Turner
Laurence Turner - avatar
+ 1
Just run through a for-loop and add the counter-variable to the string String str = ""; for (int i = 1; 1 <= 5; i++) { str += i.toString(); System.out.println(str); } (Java-Code)
5th Jan 2017, 10:09 PM
Manuel Wiltz
Manuel Wiltz - avatar
- 1
this is an example of a loop. this one will count from one to 9. for (int x = 1; x < 10; x++) { Console.WriteLine("Value of x: {0}", x); }
5th Sep 2017, 9:17 PM
Ibrahim Ali Bello
Ibrahim Ali Bello - avatar
- 1
hope it helped
5th Sep 2017, 9:17 PM
Ibrahim Ali Bello
Ibrahim Ali Bello - avatar