|
|
вернуться в форумC# What is wrong? 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? Hi, how about the case when a = 1 ? It seems like you'll output 0 which is incorrect. Re: C# What is wrong? Thank you! That was an error. |
|
|