Advertisement
SUni2020

Chapter9 C#BOOK

Jul 18th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7. // Напишете метод, който при подадено име отпечатва на конзолата "Hello, <name>!" (например "Hello, Peter!")
  8. // Напишете програма, която тества дали този метод работи правилно.
  9. // Използвайте метод с параметър string
  10.  
  11. static void Main(string[] args)
  12. {
  13. Console.Write("Please enter your name:");
  14. SayHello(Console.ReadLine());
  15. }
  16.  
  17. static void SayHello(string name)
  18. {
  19. Console.WriteLine("Hello,{0}!", name);
  20. }
  21.  
  22.  
  23.  
  24. }
  25. }
  26. using System;
  27.  
  28. namespace ConsoleApp1
  29. {
  30. class Program
  31. {
  32. // Напишете метод, който при подадено име отпечатва на конзолата "Hello, <name>!" (например "Hello, Peter!")
  33. // Напишете програма, която тества дали този метод работи правилно.
  34. // Използвайте метод с параметър string
  35.  
  36. static void Main(string[] args)
  37. {
  38. Console.Write("Please enter your name:");
  39. SayHello(Console.ReadLine());
  40. }
  41.  
  42. static void SayHello(string name)
  43. {
  44. Console.WriteLine("Hello,{0}!", name);
  45. }
  46.  
  47.  
  48.  
  49. }
  50. }
  51.  
  52. using System;
  53.  
  54. namespace Problem2
  55. {
  56. class Program
  57. {
  58. static void Main(string[] args)
  59. {
  60. //Създайте метод GetMax() с два целочислени (int) параметъра, който ръща по-голямото от двете числа.
  61. // Напишете програма, която прочита три цели числа от конзолата и отпечатва най - голямото от тях, използвайки метода GetMax().
  62. // Използвайте свойството Max(a, b, c) = Max(Max(a, b), c).
  63. Console.Write("Please enter the first number:");
  64. int firstnum = int.Parse(Console.ReadLine());
  65. Console.Write("Please enter the second number:");
  66. int secondnum = int.Parse(Console.ReadLine());
  67. Console.Write("Please enter the third number:");
  68. int thirdnum = int.Parse(Console.ReadLine());
  69.  
  70.  
  71. GetMax(firstnum,secondnum,thirdnum);
  72. }
  73. static void GetMax(int number1, int number2, int number3)
  74. {
  75.  
  76.  
  77. if (number1 > number2&& number1>number3 )
  78. {
  79. Console.WriteLine("The first number is the biggest of all");
  80.  
  81. }
  82. else if (number2 >number1&& number2> number3 )
  83. {
  84. Console.WriteLine("The second number is the biggest of all");
  85.  
  86. }
  87. else if (number3 > number2 && number3 > number2)
  88. {
  89. Console.WriteLine("The third number is the biggest of all");
  90. }
  91.  
  92.  
  93. }
  94.  
  95.  
  96.  
  97. }
  98. }
  99.  
  100.  
  101.  
  102. using System;
  103.  
  104. namespace Problem2
  105. {
  106. class Program
  107. { //Създайте метод GetMax() с два целочислени (int) параметъра, който ръща по-голямото от двете числа.
  108. // Напишете програма, която прочита три цели числа от конзолата и отпечатва най - голямото от тях, използвайки метода GetMax().
  109. // Използвайте свойството Max(a, b, c) = Max(Max(a, b), c).
  110.  
  111. //static void Main(string[] args)
  112. //{
  113. // Console.WriteLine("Insert 3 numbers to compare them:");
  114.  
  115. // int a = int.Parse(Console.ReadLine());
  116. // int b = int.Parse(Console.ReadLine());
  117.  
  118. // int c = int.Parse(Console.ReadLine());
  119.  
  120. // Console.Write("The bigest of three is: ");
  121. // Console.WriteLine(GetMax(GetMax(a, b), c));
  122. //}
  123. //static int GetMax(int a, int b)
  124. //{
  125. // return a > b ? a : b;
  126. //}
  127.  
  128. //{
  129. static int a;
  130.  
  131. static void GetMax(int first, int second)
  132. {
  133. if (first > second) a = first;
  134. else a = second;
  135. }
  136.  
  137. static void
  138. Main(string[] args)
  139. {
  140. Console.Write("Enter first number: ");
  141. a = Int32.Parse(Console.ReadLine());
  142. Console.Write("Enter second number: ");
  143. int b = Int32.Parse(Console.ReadLine());
  144. Console.Write("Enter third number: ");
  145. int c = Int32.Parse(Console.ReadLine());
  146.  
  147. GetMax(a, b);
  148. GetMax(a, c);
  149.  
  150.  
  151. Console.WriteLine("Biggest number is {0}", a);
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement