Advertisement
EmoRz

PrimesinGivenRange

May 22nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4.  
  5. namespace Methods_Bank
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             PrimePrint();
  12.         }
  13.         private static void Cub()
  14.         {
  15.             //Cube properties
  16.             var side = double.Parse(Console.ReadLine());
  17.             var typeCalc = Console.ReadLine();
  18.             //
  19.             var result = 0.0;
  20.             if (typeCalc == "face")
  21.             {
  22.                 result = FaceCub(side);
  23.             }
  24.             if (typeCalc == "space")
  25.             {
  26.                 result = spaceCub(side);
  27.             }
  28.             if (typeCalc == "volume")
  29.             {
  30.                 result = VolumeCub(side);
  31.             }
  32.             if (typeCalc == "area")
  33.             {
  34.                 result = SurfaceCub(side);
  35.             }
  36.             Console.WriteLine($"{result:F2}");
  37.         }
  38.         public static double FaceCub(double n)
  39.         {
  40.             var result = Math.Sqrt(2 * Math.Pow(n, 2));
  41.             return result;
  42.         }
  43.         public static double spaceCub(double n)
  44.         {
  45.             var result = Math.Sqrt(3 * Math.Pow(n, 2));
  46.             return result;
  47.         }
  48.         public static double VolumeCub(double n)
  49.         {
  50.             var result = (Math.Pow(n, 3));
  51.             return result;
  52.         }
  53.         public static double SurfaceCub(double n)
  54.         {
  55.             var result = 6 * (Math.Pow(n, 2));
  56.             return result;
  57.         }
  58.         private static void LongLine()
  59.         {
  60.             var x1 = double.Parse(Console.ReadLine());
  61.             var y1 = double.Parse(Console.ReadLine());
  62.             var x2 = double.Parse(Console.ReadLine());
  63.             var y2 = double.Parse(Console.ReadLine());
  64.  
  65.             var x3 = double.Parse(Console.ReadLine());
  66.             var y3 = double.Parse(Console.ReadLine());
  67.             var x4 = double.Parse(Console.ReadLine());
  68.             var y4 = double.Parse(Console.ReadLine());
  69.             //
  70.             var len1 = LineLenght(x1, y1, x2, y2);
  71.             var len2 = LineLenght(x3, y3, x4, y4);
  72.  
  73.             if (len1 > len2)
  74.             {
  75.                 var closer = CloserOrNot(x1, y1, x2, y2);
  76.                 if (closer)
  77.                 {
  78.                     Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  79.                 }
  80.                 else
  81.                 {
  82.                     Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  83.                 }
  84.             }
  85.             else
  86.             {
  87.                 var closer = CloserOrNot(x3, y3, x4, y4);
  88.                 if (closer)
  89.                 {
  90.                     Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  91.                 }
  92.                 else
  93.                 {
  94.                     Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  95.                 }
  96.             }
  97.         }
  98.  
  99.         public static bool CloserOrNot(double x1, double y1, double x2, double y2)
  100.         {
  101.             var a = Math.Sqrt(x1 * x1 + y1 * y1);
  102.             var b = Math.Sqrt(x2 * x2 + y2 * y2);
  103.             bool check = true;
  104.             if (a < b)
  105.             {
  106.                 check = true;
  107.             }
  108.             else
  109.             {
  110.                 check = false;
  111.             }
  112.             return check;
  113.         }
  114.         public static double LineLenght(double x1, double y1, double x2, double y2)
  115.         {
  116.             var lenght = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
  117.             return lenght;
  118.         }
  119.  
  120.         private static void CenterPoint1_1(double x1, double y1, double x2, double y2)
  121.         {
  122.             var c = Math.Sqrt(x1 * x1 + y1 * y1);
  123.             Math.Abs(c);
  124.             var nC = Math.Sqrt(x2 * x2 + y2 * y2);
  125.             Math.Abs(nC);
  126.             //
  127.             var x = 0.0;
  128.             var y = 0.0;
  129.  
  130.             if (c < nC)
  131.             {
  132.                 x = x1;
  133.                 y = y1;
  134.             }
  135.             if (c > nC)
  136.             {
  137.                 x = x2;
  138.                 y = y2;
  139.             }
  140.             else
  141.             {
  142.                 x = x1;
  143.                 y = y1;
  144.             }
  145.             Console.WriteLine($"({x}, {y})");
  146.         }
  147.  
  148.         private static void CenterPoint(double x1, double y1, double x2, double y2)
  149.         {
  150.             bool first = (x1 < x2) && (y1 < y2);
  151.             bool second = (x1 > x2) && (y1 > y2);
  152.             double x = 0.0;
  153.             double y = 0.0;
  154.  
  155.             if (first)
  156.             {
  157.                 x = x1;
  158.                 y = y1;
  159.             }
  160.             if (second)
  161.             {
  162.                 y = y2;
  163.                 x = x2;
  164.             }
  165.             else
  166.             {
  167.                 x = x1;
  168.                 y = y1;
  169.             }
  170.  
  171.             Console.WriteLine($"({x}, {y})");
  172.         }
  173.  
  174.         private static void PrimePrint()
  175.         {
  176.             var n = int.Parse(Console.ReadLine());
  177.             var n1 = int.Parse(Console.ReadLine());
  178.             //
  179.             List<int> isP = FindPrimesInRange(n, n1);
  180.  
  181.             for (int i = 0; i < isP.Count; i++)
  182.             {
  183.                 if (isP[i] != isP[isP.Count - 1])
  184.                 {
  185.                     Console.Write(isP[i] + ", ");
  186.                 }
  187.                 else
  188.                 {
  189.                     Console.WriteLine(isP[i]);
  190.                 }
  191.             }
  192.         }
  193.  
  194.         public static List<int> FindPrimesInRange(int startNum, int endNum)
  195.         {
  196.             List<int> nn = new List<int>();
  197.             var isPP = false;
  198.             for (int i = startNum; i <= endNum; i++)
  199.             {
  200.                 isPP = Prime(i);
  201.                 if (isPP)
  202.                 {
  203.                     nn.Add(i);
  204.                 }
  205.             }
  206.             return nn;
  207.         }
  208.  
  209.         public static bool Prime(long n)
  210.         {
  211.             if (n == 0 || n == 1)
  212.             {
  213.                 return false;
  214.             }
  215.             for (int i = 2; i <= Math.Sqrt(n); i++)
  216.             {
  217.                 if (n % i == 0)
  218.                 {
  219.                     return false;
  220.                 }
  221.             }
  222.             return true;
  223.         }
  224.  
  225.         private static void Fibb()
  226.         {
  227.             var num = long.Parse(Console.ReadLine());
  228.             var n = Fib(num);
  229.             Console.WriteLine(n);
  230.         }
  231.  
  232.         public static long Fib(long n)
  233.         {
  234.             if (n == 0)
  235.             {
  236.                 return 1;
  237.             }
  238.             if (n == 1)
  239.             {
  240.                 return 1;
  241.             }
  242.             if (n == 2)
  243.             {
  244.                 return 2;
  245.             }
  246.             long fi = Fib(n - 1) + Fib(n - 2);
  247.             return fi;
  248.  
  249.         }
  250.  
  251.         private static void ReversedData()
  252.         {
  253.             var num = Console.ReadLine();
  254.             var newW = Reversed((num));
  255.             double rever = Convert.ToDouble(newW);
  256.             Console.WriteLine(rever);
  257.         }
  258.  
  259.         public static string Reversed(string str)
  260.         {
  261.             string newnum = "";
  262.             for (int i = str.Length - 1; i >= 0; i--)
  263.             {
  264.                 newnum += str[i];
  265.             }
  266.             return newnum;
  267.         }
  268.         public static void EnglishName(long n)
  269.         {
  270.             if (n < 0)
  271.             {
  272.                 n *= (-1);
  273.             }
  274.             long lastDigit = n % 10;
  275.             var str = "";
  276.             switch (lastDigit)
  277.             {
  278.                 case 0: str = "zero"; break;
  279.                 case 1: str = "one"; break;
  280.                 case 2: str = "two"; break;
  281.                 case 3: str = "three"; break;
  282.                 case 4: str = "four"; break;
  283.                 case 5: str = "five"; break;
  284.                 case 6: str = "six"; break;
  285.                 case 7: str = "seven"; break;
  286.                 case 8: str = "eight"; break;
  287.                 case 9: str = "nine"; break;
  288.             }
  289.             Console.WriteLine(str);
  290.  
  291.         }
  292.  
  293.         private static void GetMaxx()
  294.         {
  295.             var a = int.Parse(Console.ReadLine());
  296.             var b = int.Parse(Console.ReadLine());
  297.             var c = int.Parse(Console.ReadLine());
  298.             //
  299.             var max = 0;
  300.             if (GetMax(a, b) > c)
  301.             {
  302.                 max = GetMax(a, b);
  303.             }
  304.             else
  305.             {
  306.                 max = c;
  307.             }
  308.             Console.WriteLine(max);
  309.         }
  310.  
  311.         public static int GetMax(int a, int b)
  312.         {
  313.             var greatest = 0;
  314.             if (a > b)
  315.             {
  316.                 greatest = a;
  317.             }
  318.             else
  319.             {
  320.                 greatest = b;
  321.             }
  322.             return greatest;
  323.         }
  324.  
  325.         private static void Greeting()
  326.         {
  327.             //Name => Greeting
  328.             var input = Console.ReadLine();
  329.             string prt = Hello(input);
  330.             Console.WriteLine(prt);
  331.         }
  332.  
  333.         public static string Hello(string h)
  334.         {
  335.             var hello = $"Hello, {h}!";
  336.             return hello;
  337.         }
  338.  
  339.     }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement