Advertisement
EmoRz

MethodAndDebug

May 18th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Methods_Debug
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             PrimePrint();
  11.         }
  12.  
  13.         private static void PrimePrint()
  14.         {
  15.             var n = int.Parse(Console.ReadLine());
  16.             var n1 = int.Parse(Console.ReadLine());
  17.             //
  18.             List<int> isP = FindPrimesInRange(n, n1);
  19.  
  20.             for (int i = 0; i < isP.Count; i++)
  21.             {
  22.                 if (isP[i] != isP[isP.Count - 1])
  23.                 {
  24.                     Console.Write(isP[i] + ", ");
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.WriteLine(isP[i]);
  29.                 }
  30.             }
  31.         }
  32.  
  33.         public static List<int> FindPrimesInRange(int startNum, int endNum)
  34.         {
  35.             List<int> nn = new List<int>();
  36.             var isPP = false;
  37.             for (int i = startNum; i <= endNum; i++)
  38.             {
  39.                 isPP = Prime(i);
  40.                 if (isPP)
  41.                 {
  42.                     nn.Add(i);
  43.                 }
  44.             }
  45.             return nn;
  46.         }
  47.  
  48.         public static bool Prime(long n)
  49.         {
  50.             if (n==0 || n==1)
  51.             {
  52.                 return false;
  53.             }
  54.             for (int i = 2; i <= Math.Sqrt(n); i++)
  55.             {
  56.                 if (n % i == 0)
  57.                 {
  58.                    return false;
  59.                 }
  60.             }
  61.             return true;
  62.         }
  63.  
  64.         private static void Fibb()
  65.         {
  66.             var num = long.Parse(Console.ReadLine());
  67.             var n = Fib(num);
  68.             Console.WriteLine(n);
  69.         }
  70.  
  71.         public static long Fib(long n)
  72.         {
  73.             if (n ==0)
  74.             {
  75.                 return 1;
  76.             }
  77.             if (n == 1)
  78.             {
  79.                 return 1;
  80.             }
  81.             if (n == 2)
  82.             {
  83.                 return 2;
  84.             }
  85.             long fi = Fib(n - 1) + Fib(n - 2);
  86.             return fi;
  87.            
  88.         }
  89.  
  90.         private static void ReversedData()
  91.         {
  92.             var num = Console.ReadLine();
  93.             var newW = Reversed((num));
  94.             double rever = Convert.ToDouble(newW);
  95.             Console.WriteLine(rever);
  96.         }
  97.  
  98.         public static string Reversed(string str)
  99.         {
  100.             string newnum ="";
  101.             for (int i = str.Length-1; i >=0; i--)
  102.             {
  103.                 newnum += str[i];
  104.             }
  105.             return newnum;
  106.         }
  107.         public static void EnglishName(long n)
  108.         {            
  109.             long lastDigit = n % 10;
  110.             var str = "";
  111.             switch (lastDigit)
  112.             {
  113.                 case 0: str = "zero"; break;
  114.                 case 1: str = "one"; break;
  115.                 case 2: str = "two"; break;
  116.                 case 3: str = "three"; break;
  117.                 case 4: str = "four"; break;
  118.                 case 5: str = "five"; break;
  119.                 case 6: str = "six"; break;
  120.                 case 7: str = "seven"; break;
  121.                 case 8: str = "eight"; break;
  122.                 case 9: str = "nine"; break;
  123.             }
  124.             Console.WriteLine(str);
  125.  
  126.         }
  127.  
  128.         private static void GetMaxx()
  129.         {
  130.             var a = int.Parse(Console.ReadLine());
  131.             var b = int.Parse(Console.ReadLine());
  132.             var c = int.Parse(Console.ReadLine());
  133.             //
  134.             var max = 0;
  135.             if (GetMax(a, b) > c)
  136.             {
  137.                 max = GetMax(a, b);
  138.             }
  139.             else
  140.             {
  141.                 max = c;
  142.             }
  143.             Console.WriteLine(max);
  144.         }
  145.  
  146.         public static int GetMax(int a, int b)
  147.         {
  148.             var greatest = 0;
  149.             if (a>b)
  150.             {
  151.                 greatest = a;
  152.             }
  153.             else
  154.             {
  155.                 greatest = b;
  156.             }
  157.             return greatest;
  158.         }
  159.  
  160.         private static void Greeting()
  161.         {
  162.             //Name => Greeting
  163.             var input = Console.ReadLine();
  164.             string prt = Hello(input);
  165.             Console.WriteLine(prt);
  166.         }
  167.  
  168.         public static string Hello(string h)
  169.         {
  170.             var hello = $"Hello, {h}!";
  171.             return hello;
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement