|
|
вернуться в форумWhere is error? 1068 using System; class Program { static void Main() { int a = 1; int N; N = int.Parse(Console.ReadLine()); if(Math.Abs(N)<10000) if (N >= 1) Console.WriteLine(((a + N) / 2) * N); else Console.WriteLine(((a+Math.Abs(N)) / 2) * N+1); else Console.WriteLine("ERROR"); } } Edited by author 18.09.2013 00:10 Edited by author 18.09.2013 00:12 Re: Where is error? 1068 what if the output is N=2 (a+N)/2=1.5 1.5*2=3.0 this is not an integer better: (N+1)*N div 2 if N<0: -((N+1)*N div 2) + 1 |
|
|