Advertisement
Guest User

Untitled

a guest
May 7th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 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 NumberCalc_6
  8. {
  9.     class NumberCalc_6
  10.     {      
  11.         static dynamic GetMin(dynamic[] arr)
  12.         {
  13.             dynamic minValue = arr[0];
  14.             for (int i = 1; i < arr.Length; i++)
  15.             {
  16.                 if (minValue > arr[i])
  17.                 {
  18.                     minValue = arr[i];
  19.                 }
  20.             }
  21.             return minValue;
  22.         }
  23.         static dynamic GetMax(dynamic[] arr)
  24.         {
  25.             dynamic maxValue = arr[0];
  26.             for (int i = 1; i < arr.Length; i++)
  27.             {
  28.                 if (maxValue < arr[i])
  29.                 {
  30.                     maxValue = arr[i];
  31.                 }
  32.             }
  33.             return maxValue;
  34.         }
  35.         static dynamic GetSum(dynamic[] arr)
  36.         {
  37.             dynamic sum = arr[0];
  38.             for (int i = 1; i < arr.Length; i++)
  39.             {
  40.                 sum += arr[i];
  41.             }
  42.             return sum;
  43.         }
  44.         static dynamic GetProduct(dynamic[] arr)
  45.         {
  46.             dynamic product = arr[0];
  47.             for (int i = 1; i < arr.Length; i++)
  48.             {
  49.                 product *= arr[i];
  50.             }
  51.             return product;
  52.         }
  53.         static dynamic GetAverage(dynamic[] arr)
  54.         {
  55.             dynamic sum = arr[0];
  56.             for (int i = 1; i < arr.Length; i++)
  57.             {
  58.                 sum += arr[i];
  59.             }
  60.             sum = sum / arr.Length;
  61.             return sum;
  62.         }
  63.         static void Main(string[] args)
  64.         {
  65.             dynamic[] doubleArr = { 1.1, 2.2, 0.3, 1.4, 6.5, 6.6, 1.7, 8.8, 0.9 };
  66.             dynamic[] intArr = { 1, 2, 31, 4, 15, 6, 17, 18, 9 };
  67.             Console.WriteLine("Min member -> double {0}  integer {1}",GetMin(doubleArr),GetMin(intArr));
  68.             Console.WriteLine("Max member -> double {0}  integer {1}", GetMax(doubleArr), GetMax(intArr));
  69.             Console.WriteLine("Sum of elements -> double {0}  integer {1}",GetSum(doubleArr),GetSum(intArr));
  70.             Console.WriteLine("Products of elements -> double {0}  integer {1}", GetProduct(doubleArr), GetProduct(intArr));
  71.             Console.WriteLine("Avarage -> double {0}  integer {1}", GetAverage(doubleArr), GetAverage(intArr));
  72.            
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement