SHARE
TWEET

Практикум 4, задание 2, номер 11

Infiniti_Inter Sep 16th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace mainSolution
  8. {
  9.     public class MyException : Exception
  10.     {
  11.         public MyException(string messege) : base(message: messege + "\n\n\n Exception founded by Decibit\n\n\n") { }
  12.         public MyException() : base()
  13.         {
  14.  
  15.         }
  16.         public void Messsage()
  17.         {
  18.             Console.WriteLine("\n\n\n\n\n\n Invalid number, please enter a number from 1 to 12 \n\n\n\n\n\n");
  19.         }
  20.  
  21.  
  22.     }
  23.     class Input
  24.     {
  25.         private static IEnumerator<string> getin()
  26.         {
  27.             while (true)
  28.                 foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))
  29.                     yield return s;
  30.         }
  31.  
  32.         private IEnumerator<string> inp = getin();
  33.  
  34.         public string GetString() { inp.MoveNext(); return inp.Current; }
  35.         public int GetInt() { return int.Parse(GetString()); }
  36.         public long GetLong() { return long.Parse(GetString()); }
  37.         public double GetDouble() { return double.Parse(GetString()); }
  38.     }
  39.  
  40.     static class Program
  41.     {
  42.         static public Input cin = new Input();
  43.  
  44.  
  45.         static void Main(string[] args)
  46.         {
  47.             int n = cin.GetInt();
  48.             long sum = 0;
  49.             long fact = 1;
  50.             int a = 1;
  51.             for (int i = 1; i <= n; ++i)
  52.             {
  53.                 fact *= i;
  54.                 sum += a * fact;
  55.                 a = -a;
  56.             }
  57.             Console.WriteLine(sum);
  58.         }
  59.  
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top