Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. int[] x = new int[20];
  4. Random rnd = new Random();
  5. int brojacNeparnih = 0;
  6.  
  7. for (int i = 0; i < x.Length; i++)
  8. {
  9. x[i] = rnd.Next(1, 21);
  10.  
  11. if (x[i] % 2 != 0)
  12. {
  13. brojacNeparnih++;
  14. }
  15. }
  16. noviNiz(x, brojacNeparnih);
  17. Console.WriteLine("Srednja vrednost je: {0}", srednjaVrednost(x));
  18. }
  19.  
  20. static void noviNiz(int[] a, int brNeparnih)
  21. {
  22. int[] y = new int[brNeparnih];
  23. int brojac = 0;
  24.  
  25. for (int i = 0; i < a.Length; i++)
  26. {
  27. if (a[i] % 2 != 0)
  28. {
  29. y[brojac] = a[i];
  30. brojac++;
  31. }
  32. }
  33.  
  34. foreach (var item in y)
  35. {
  36. Console.WriteLine(item);
  37. }
  38.  
  39. }
  40.  
  41. static decimal srednjaVrednost(int[] a)
  42. {
  43. int zbir = 0;
  44. for (int i = 0; i < a.Length; i++)
  45. {
  46. zbir += a[i];
  47. }
  48.  
  49. return (decimal)zbir / a.Length;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement