Advertisement
wingman007

MagSolutionsExample2023

Oct 28th, 2023 (edited)
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.36 KB | None | 0 0
  1. // See https://aka.ms/new-console-template for more information
  2. //Console.WriteLine("Hello, World!");
  3. // Zad 1.
  4. //Console.WriteLine("2011 to BIN {0}.", Convert.ToString(2093, 2));
  5. //Console.WriteLine("2011 to OCT {0}.", Convert.ToString(2093, 8));
  6. //Console.WriteLine("2011 to HEX {0}.", Convert.ToString(2093, 16));
  7.  
  8.  
  9. // Test 1 - 2 I
  10. //double x = 3.4, y = 5.6, z = 7.8;
  11.  
  12. //Console.WriteLine(
  13. //    ((Math.Pow(x, 7.0) * y * z) - 3.3 * Math.Abs(x + Math.Pow(y, 1/4.0))) /
  14. //    Math.Pow(10.0, 7.0) + Math.Sqrt(Math.Log(4.0))
  15. //);
  16.  
  17.  
  18. // Zad 36 d
  19. //int x = 2;
  20. //int y = 3;
  21. //int z = 4;
  22.  
  23. //Console.WriteLine(x > 0 && y > 0 && z > 0);
  24.  
  25. // zad 102.
  26.  
  27. //int a1, a2, a3, a4, a5, a6;
  28.  
  29. //for (int number = 0; number <= 999999; number++)
  30. //{
  31. //    a1 = (number / 100000);
  32. //    a2 = (number / 10000) % 10;
  33. //    a3 = ((number / 1000) % 10);
  34. //    a4 = ((number / 100) % 10);
  35. //    a5 = ((number / 10) % 10);
  36. //    a6 = number % 10;
  37.  
  38. //    if (a1 + a2 + a3 == a4 + a5 + a6)
  39. //    {
  40. //        Console.WriteLine($"{number} is a lucky number");
  41. //    }
  42. //}
  43.  
  44. // zad 164
  45. //int[] A = {2, 2};
  46. //int[] B = {3, 4};
  47. //int[] C = {5, 6};
  48.  
  49. //double a = Math.Sqrt(Math.Pow((B[0] - A[0]), 2) + Math.Pow((B[1] - A[1]), 2));
  50. //Console.WriteLine(a);
  51. //double b = Math.Sqrt(Math.Pow((C[0] - B[0]), 2) + Math.Pow((C[1] - B[1]), 2));
  52. //Console.WriteLine(b);
  53. //double c = Math.Sqrt(Math.Pow((C[0] - A[0]), 2) + Math.Pow((C[1] - A[1]), 2));
  54. //Console.WriteLine(c);
  55.  
  56. //if (a + b > c && a + c > b && b + c > a)
  57. //{
  58. //    Console.WriteLine("This is a triangle");
  59. //    double s = (a + b + c) / 2;
  60. //    double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
  61. //    Console.WriteLine($"The area is {area}");
  62. //}
  63. //else
  64. //{
  65. //    Console.WriteLine("Thi si snot a triangle");
  66. //}
  67.  
  68.  
  69. // Zad 405
  70. int n = 0;
  71. bool isNumber = false;
  72. do
  73. {
  74.     Console.Write("Please, enter the lenght of the array [2,25] ");
  75.     n = int.Parse(Console.ReadLine());
  76. } while (n < 2 || n > 25);
  77. //    isNumber = int.TryParse(Console.ReadLine(), out n);
  78. //} while (!isNumber || (n < 2 || n > 25));
  79.  
  80. int[] myArray = new int[n];
  81. for (int i = 0; i < myArray.Length; i++)
  82. {
  83.     Console.Write($"Please enter a value for element myArrey[{i}] = ");
  84.     myArray[i] = int.Parse(Console.ReadLine());
  85. }
  86.  
  87. for (int i = 0; i < myArray.Length; i++)
  88. {
  89.     Console.WriteLine($"myArray[{i}] = {myArray[i]}");
  90. }
  91.  
  92. int k = 0;
  93. Console.Write("Please, enter k = ");
  94. k = int.Parse(Console.ReadLine());
  95. Console.WriteLine(Prod(myArray, k));
  96.  
  97. static int Prod(int[] myArray, int k)
  98. {
  99.     int sum = 0;
  100.     for (int i = 0; i < myArray.Length; i++)
  101.     {
  102.         if (myArray[i] > 0 && myArray[i] < k)
  103.         {
  104.             sum += myArray[i];
  105.         }
  106.     }
  107.     return sum;
  108. }
  109.  
  110. int counter = 0;
  111. int a1 = 0;
  112. int a2 = 0;
  113. int a3 = 0;
  114. for (int i = 0; i < myArray.Length; i++)
  115. {
  116.     if (myArray[i] >= 100 && myArray[i] <= 666)
  117.     {
  118.         a1 = myArray[i] / 100;
  119.         a2 = (myArray[i] / 10) % 10;
  120.         a3 = myArray[i] % 10;
  121.  
  122.         //string numberString = myArray[i].ToString();
  123.         //a1 = numberString[0];
  124.         //a2 = numberString[1];
  125.         //a3 = numberString[2];
  126.  
  127.         if ((a1 + a2 + a3) % 3 == 0)
  128.         {
  129.             counter++;
  130.         }
  131.     }
  132. }
  133.  
  134. Console.WriteLine(counter);
  135.  
  136.  
  137. // Zad 363
  138. //Console.WriteLine(counter);
  139.  
  140. //char myChar = 'A';
  141. //Console.WriteLine((int)myChar);
  142.  
  143. //string unicode = "&#1075;&#1088;&#1072;&#1072;";
  144. //string result = unicode.Replace("&#1075;", "г");
  145.  
  146. //Console.WriteLine(result);
  147.  
  148. // ------------------------------------------
  149. //Console.WriteLine("2010 to BIN {0}.", Convert.ToString(2010, 2));
  150. //Console.WriteLine("2010 to OCT {0}.", Convert.ToString(2010, 8));
  151. //Console.WriteLine("2010 to HEX {0}.", Convert.ToString(2010, 16));
  152.  
  153. double H = 2.3;
  154. double R = 5.0;
  155. Console.WriteLine("Surface s = {0}", 2 * Math.PI * R * H);
  156. Console.WriteLine("Full Surface S = {0}", 2 * Math.PI * R * H + 2 * Math.PI * Math.Pow(R, 2));
  157.  
  158. // Zad 37 - 4
  159. bool s = false;
  160. bool t = true;
  161.  
  162. Console.WriteLine(!(s || t) && s || !t);
  163.  
  164. // Zad 99
  165. double sum = 0;
  166. for (int i = 1; i < 100000; i++)
  167. {
  168.     if (i % 2 == 0)
  169.     {
  170.         sum -= 1.0/i;
  171.     }
  172.     else
  173.     {
  174.         sum += 1.0 / i;
  175.     }
  176. }
  177.  
  178. Console.WriteLine(sum);
  179.  
  180. sum = 0;
  181.  
  182. for (int i = 100000; i >= 1; i--)
  183. {
  184.     if (i % 2 == 0)
  185.     {
  186.         sum -= 1.0 / i;
  187.     }
  188.     else
  189.     {
  190.         sum += 1.0 / i;
  191.     }
  192. }
  193.  
  194. Console.WriteLine(sum);
  195.  
  196. double sumPositive = 0;
  197. double sumNegative = 0;
  198.  
  199. for (int i = 1; i <= 100000; i++)
  200. {
  201.     if (i % 2 == 0)
  202.     {
  203.         sumNegative -= 1.0 / i;
  204.     }
  205.     else
  206.     {
  207.         sumPositive += 1.0 / i;
  208.     }
  209. }
  210.  
  211. Console.WriteLine(sumNegative);
  212. Console.WriteLine(sumPositive);
  213.  
  214.  
  215. sumPositive = 0;
  216. sumNegative = 0;
  217.  
  218. for (int i = 100000; i >= 1; i--)
  219. {
  220.     if (i % 2 == 0)
  221.     {
  222.         sumNegative -= 1.0 / i;
  223.     }
  224.     else
  225.     {
  226.         sumPositive += 1.0 / i;
  227.     }
  228. }
  229.  
  230. Console.WriteLine(sumNegative);
  231. Console.WriteLine(sumPositive);
  232.  
  233.  
  234.  
  235. // Zad 163 zad 90
  236. int a = 2;
  237. int b = 3;
  238. int c = 4;
  239. int d = 5;
  240. int p = 6;
  241. int q = -7;
  242.  
  243. // Console.WriteLine(a * x + b * y + c * z + d = 0);
  244.  
  245. for (int x = p; x < q; x++)
  246. {
  247.     for (int y = p; y < q; y++)
  248.     {
  249.         for (int z = p; z < q; z++)
  250.         {
  251.             if (a*x + b*y + c*z + d == 0)
  252.             {
  253.                 Console.WriteLine($"x = {x} y = {y} z = {z}");
  254.                 Console.ReadKey(true);
  255.             }
  256.         }
  257.     }
  258. }
  259.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement