forked from Twiggecode/Integer-Sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyCatererSequence.cs
47 lines (40 loc) · 1.09 KB
/
LazyCatererSequence.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace DefaultNamespace
{
public static class LazyCatererSequence
{
public static int CalculateLazyCaterSequence(int n)
{
if(n == 0)
{
return 1;
}
//formula is p = (n^2 + n + 2) / 2. Easy~
return ((n * n + n + 2) / 2);
}
public static void Run()
{
int nTH;
Console.WriteLine("Please enter a integer");
while (true)
{
string input = Console.ReadLine();
try
{
nTH = Convert.ToInt32(input);
if (nTH < 0)
{
throw new Exception("s");
}
Console.WriteLine(CalculateLazyCaterSequence(nTH));
break;
}
catch (Exception e)
{
Console.WriteLine("Invalid, please enter an valid number");
Console.WriteLine(e);
}
}
}
}
}
}