+ 18
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int Levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(Levels)); } static int Points(int Levels) { //your code goes here if (Levels == 1) return 1; return Levels + Points(Levels - 1); } } }
9th Jan 2021, 5:25 PM
08. Dharma Soegiantoro
08. Dharma Soegiantoro - avatar
+ 1
That's a solution, only if the input is between 1 and 3. However, the input range is not given in the question. It only mentions that the point starts from 1. What if the input is 4, 5, 10, 1000? Apparently, multiple if-else statements isn't ideal.
17th Dec 2020, 12:23 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
It should be a recursive function and increment by 1 for each levels: ----------------------------------------------------------------------------------- using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int Levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(Levels)); } static int Points(int Levels) { //your code goes here if (Levels == 1) return 1; return Levels + Points(Levels - 1); } } }
2nd Mar 2021, 4:51 PM
Gashaye Anley
+ 1
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int Levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(Levels)); } static int Points(int Levels) { //your code goes here if (Levels == 1) return 1; return Levels + Points(Levels - 1); } } } this is the answer
30th Mar 2021, 5:31 AM
ANIKET SINGH
ANIKET SINGH - avatar
+ 1
One line solution using lambdas and ternary operator static Func<int, int> Points = levels => levels == 1 ? 1 : levels + Points(levels - 1);
20th Aug 2021, 7:45 AM
David García Prados
0
what u want to do?
17th Dec 2020, 12:18 PM
durian
durian - avatar
0
why dont try for loop? get current level,and add points from cur point to 1
17th Dec 2020, 12:23 PM
durian
durian - avatar
0
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int Levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(Levels)); } static int Points(int Levels) { //your code goes here if (Levels == 1) return 1; return Levels + Points(Levels - 1); } } }
7th Feb 2021, 5:07 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
0
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(levels)); } static int Points(int levels) { //your code goes here int points1 = 0; for (; levels > 0;levels--) { points1 += levels; } return points1; } } }
16th Apr 2022, 8:10 PM
Martin Chakarov
0
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(levels)); } static int Points(int levels) { int n=1; int points=0; //your code goes here while(n<=levels) { Points=n+points; n++; } return points; } } }
18th Sep 2022, 5:52 PM
zaki Habeshiye
- 3
static int Points(int levels) { int pts = 0; while (levels >0) { pts = pts + levels; levels = levels - 1; } return pts; }
8th Mar 2021, 6:54 PM
Ömer Karagöz
Ömer Karagöz - avatar