ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

C# What is wrong?
Posted by AC_Cobra 2 Apr 2012 20:05
I have checked all known numbers - result is right. When I submit code, system writes: Wrong answer. Where is error? Thank You!

using System;

class Program
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int r = 0;
        if (a <= System.Math.Abs(10000))
        {
            if (a > 1)
            {
                for (int i = 1; i <= a; i++)
                {
                    r += i;
                }
            }
            if (a < 1)
            {
                for (int i = 1; i >= a; i--)
                {
                    r += i;
                }
            }
            Console.WriteLine(r);
        }
        else
            throw new Exception("Wrong number");
    }
}
Re: C# What is wrong?
Posted by morbidel 2 Apr 2012 20:53
Hi,
how about the case when a = 1 ? It seems like you'll output 0 which is incorrect.
Re: C# What is wrong?
Posted by AC_Cobra 3 Apr 2012 12:33
Thank you! That was an error.