ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion 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 i = 0;
while (n != 1){
if (n >= 1){
i+= n;
n--;
}
else if (n <= 0){
i+= n;
n++;
}
}
Console.Write(i + 1);
}
}
}
Re: Решение C# | Solution C#
Posted by Roman123 8 Nov 2017 16:16
using System;

class Puzzle
{
public static void Main()
{
(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