Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 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 ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static int ZwróćMaksimum(int [] x)
  12. {
  13. int [] tabx = x;
  14. int maksimum = tabx[0];
  15. for (int i = 0; i < tabx.Length; i++)
  16. {
  17. if (tabx[i] > maksimum)
  18. {
  19. maksimum = tabx[i];
  20. }
  21. }
  22.  
  23. return maksimum;
  24. }
  25. static void Main(string[] args)
  26. {
  27. //1. Dodaj do solucji program i utwórz w nim funkcję static int ZwróćMaksimum, która pobiera jako parametr tablicę int[].
  28. //Zaobserwuj, czy możesz zoptymalizować kod, wyodrębniając powtarzające się bloki kodu i tworząc dodatkowe funkcje.
  29. //W programie przetestuj działanie stworzonych funkcji. Program powinien działać w pętli do ... while, dopóki użytkownik
  30. //nie wciśnie klawisza, który kończy działanie programu.
  31.  
  32. int x,y;
  33. Random los = new Random();
  34. do
  35. {
  36. Console.WriteLine("Podaj wielkość tablicy, liczba 0 kończy działanie programu");
  37. x = Convert.ToInt32(Console.ReadLine());
  38. int[] tab = new int[x];
  39. for (int i = 0; i < tab.Length; i++)
  40. {
  41. y = los.Next(0, 31);
  42. tab[i] = y;
  43. }
  44. for (int i = 0; i < tab.Length; i++)
  45. {
  46. Console.Write("{0} ", tab[i]);
  47. }
  48. Console.WriteLine("Maksimum w tej tablicy to " + ZwróćMaksimum(tab));
  49. } while (x != 0);
  50.  
  51.  
  52. Console.WriteLine("Koniec programu");
  53. Console.ReadKey();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement