|
|
back to boardDiscussion of Problem 1068. SumРешение C# | Solution C# Posted by Viktor 4 Apr 2017 04:22 using System; namespace t1068{ class Program{ public static void Main(string[] args){ int n = int.Parse(Console.ReadLine()); int i = 0; while (n != 1){ if (n >= 1){ i+= n; n--; } else if (n <= 0){ i+= n; n++; } } Console.Write(i + 1); //Console.ReadKey(); } } } Re: Решение C# | Solution C# using System; class Puzzle { public static void Main() { var n = int.Parse(Console.In.ReadLine()); (int start, int end) = n > 1 ? (1, n) : (n, 1); int sum = 0; for (int i = start; i <= end; i++) sum += i; Console.WriteLine(sum); } } Re: Решение C# | Solution C# Posted by Hesamom 11 Nov 2017 20:18 static int Proccess(int input) { if (input == 1) { return 2; } else if (input == 0) { return 1; } bool isInputNegative = false; if (input < 0) { input = input * -1; isInputNegative = true; } int sum = 0; for (int i = 1; i < input + 1; i++) { sum += i; } if (isInputNegative) { sum = sum * -1; sum++; } return sum; } more understandable :D Edited by author 11.11.2017 20:22 |
|
|