Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.                    
  5. public class Program
  6. {
  7.     private static int [] A = new int[16];
  8.    
  9.     public static int MAX()
  10.     {
  11.         int result = A[0];
  12.        
  13.         for(int i = 1; i <= A.Length - 1; i++)
  14.         {
  15.             if(A[i] > A[i - 1])
  16.                 result = A[i];
  17.         }
  18.        
  19.         return result;
  20.     }
  21.    
  22.         public static int MIN()
  23.     {
  24.         int result = A[0];
  25.        
  26.         for(int i = 1; i <= A.Length - 1; i++)
  27.         {
  28.             if(A[i] < A[i - 1])
  29.                 result = A[i];
  30.         }
  31.        
  32.         return result;
  33.     }
  34.  
  35.     public static void evenNumber()
  36.     {
  37.         List<int> itemsA = new List<int>();
  38.         List<int> itemsB = new List<int>();
  39.        
  40.         for(int i = 0; i <= A.Length - 1; i++)
  41.         {
  42.             if(A[i] % 2 == 0)
  43.             {
  44.                 itemsA.Add(A[i]);
  45.             }
  46.             else
  47.             {
  48.                 itemsB.Add(A[i]);  
  49.             }
  50.            
  51.             var result = from item in itemsA
  52.                 orderby item ascending
  53.                 select item;
  54.                
  55.             foreach(var item in result)
  56.             {
  57.                 Console.Write("{},", item);
  58.             }
  59.            
  60.             var result2 = from item in itemsB
  61.                 orderby item descending
  62.                 select item;
  63.            
  64.             foreach(var item in result2)
  65.             {
  66.                 Console.Write("{},", item);
  67.             }
  68.  
  69.         }
  70.     }
  71.    
  72.     public static void Main()
  73.     {
  74.  
  75.    
  76.         Random r = new Random();
  77.         for(int i = 0; i <= A.Length - 1; i++)
  78.         {
  79.             A[i] = r.Next(30, 60);
  80.         }
  81.        
  82.         Console.WriteLine($"Największa wartość: {0}", MAX());
  83.         Console.WriteLine($"Najmniejsza wartość: {0}", MIN());
  84.        
  85.         for(int j = 0; j <= A.Length - 1; j++)
  86.             A[i] = 0;
  87.        
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement