Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int[] x = new int[20];
- Random rnd = new Random();
- int brojacNeparnih = 0;
- for (int i = 0; i < x.Length; i++)
- {
- x[i] = rnd.Next(1, 21);
- if (x[i] % 2 != 0)
- {
- brojacNeparnih++;
- }
- }
- noviNiz(x, brojacNeparnih);
- Console.WriteLine("Srednja vrednost je: {0}", srednjaVrednost(x));
- }
- static void noviNiz(int[] a, int brNeparnih)
- {
- int[] y = new int[brNeparnih];
- int brojac = 0;
- for (int i = 0; i < a.Length; i++)
- {
- if (a[i] % 2 != 0)
- {
- y[brojac] = a[i];
- brojac++;
- }
- }
- foreach (var item in y)
- {
- Console.WriteLine(item);
- }
- }
- static decimal srednjaVrednost(int[] a)
- {
- int zbir = 0;
- for (int i = 0; i < a.Length; i++)
- {
- zbir += a[i];
- }
- return (decimal)zbir / a.Length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement