+ 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);
}
}
}
+ 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.
+ 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);
}
}
}
+ 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
+ 1
One line solution using lambdas and ternary operator
static Func<int, int> Points = levels => levels == 1 ? 1 : levels + Points(levels - 1);
0
what u want to do?
0
why dont try for loop?
get current level,and add points from cur point to 1
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);
}
}
}
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;
}
}
}
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;
}
}
}
- 3
static int Points(int levels)
{
int pts = 0;
while (levels >0) {
pts = pts + levels;
levels = levels - 1;
}
return pts;
}