Advertisement
Guest User

Untitled

a guest
May 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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 ConsoleApplication13
  8. {
  9. class Program
  10. {
  11. static int Vstup(ref int cislo)
  12. {
  13. int pruchod = 0;
  14. Console.WriteLine("Zadejte cislo (0=konec)");
  15. do
  16. {
  17. if (pruchod > 0) Console.WriteLine("Nebylo zadano cele cislo.");
  18.  
  19. pruchod++;
  20.  
  21. } while (!(int.TryParse(Console.ReadLine(), out cislo)));
  22. return cislo;
  23. }
  24. static void Zadat()
  25. {
  26. int cislo = 0;
  27. int pocet = 1;
  28. int max1 = 0, max2 = 0;
  29. do
  30. {
  31. Vstup(ref cislo);
  32. if (pocet == 1)
  33. {
  34. max1 = cislo;
  35. max2 = 0;
  36.  
  37. }
  38.  
  39. if (cislo != 0)
  40. {
  41. if (cislo > max1)
  42. {
  43. max2 = max1;
  44. max1 = cislo;
  45. }
  46. else if (cislo > max2 && cislo != max1)
  47. {
  48. max2 = cislo;
  49. }
  50. }
  51. pocet++;
  52. } while (cislo != 0);
  53. if (pocet < 2) Console.WriteLine("Zadejte alespon 2 cisla");
  54. Console.WriteLine("Druhe nejvyssi cislo v rade je " + max2);
  55. }
  56.  
  57. static void Main(string[] args)
  58. {
  59. char volba = '9';
  60. do
  61. {
  62. Console.Clear();
  63. if (volba == '1') Zadat();
  64. Console.WriteLine("1..Zadat ciselnou radu\n-----------------\n9..Konec");
  65. volba = Console.ReadKey().KeyChar;
  66. } while (volba != '9');
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement