Advertisement
Infiniti_Inter

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

Sep 16th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  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.         static double getSqrt(double a, double n, double e = 1e-10)
  45.         {
  46.             double x0 = a / n;
  47.             double x = ((n - 1) * x0 + a / Math.Pow(x0, n - 1)) / n;
  48.             while (Math.Abs(x0 - x) >= e)
  49.             {
  50.                 x0 = x;
  51.                 x = ((n - 1) * x0 + a / Math.Pow(x0, n - 1)) / n;
  52.             }
  53.             return x;
  54.         }
  55.         static void Main(string[] args)
  56.         {
  57.             double a = cin.GetDouble();
  58.             int A = Convert.ToInt32(Math.Ceiling(a));
  59.             double save_a = a;
  60.             double b = cin.GetDouble();
  61.             int B = Convert.ToInt32(b);
  62.             double h = cin.GetDouble();
  63.             double ans = 0;
  64.             for (int i = 1; a <= b; ++i)
  65.             {
  66.                 Console.WriteLine($"sqrt[i] = {getSqrt(a, i)}");
  67.                 ans += getSqrt(a, i);
  68.                 a += h;
  69.             }
  70.             Console.WriteLine($"sum = {ans}");
  71.             for (int x = A; x <= B - 2; x++)
  72.                 for (int y = x + 1; y <= B - 1; y++)
  73.                     for (int z = y + 1; z <= B; z++)
  74.                     {
  75.                         if (x + y == z)
  76.                         {
  77.                             Console.WriteLine($"x = {x}, y = {y}, z = {z}");
  78.                         }
  79.                     }
  80.  
  81.             if (save_a < 2)
  82.                 Console.WriteLine("No solution");
  83.             else
  84.                 Console.WriteLine("n = 1");
  85.         }
  86.  
  87.  
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement