ellapt

T9.14.CalcIntSetNumbers

Jan 21st, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System;
  2.  
  3. class CalcIntSetNumbers
  4. {
  5. static int Minimum(params int[] numbers)
  6. {
  7. int minNum = numbers[0];
  8. int length = numbers.Length;
  9. for (int i = 0; i < length; i++)
  10. {
  11. if (length > 0)
  12. {
  13. if (numbers[i] < minNum)
  14. {
  15. minNum = numbers[i];
  16. }
  17. }
  18. else
  19. {
  20. return 0;
  21. }
  22. }
  23. return minNum;
  24. }
  25. static int Maximum(params int[] numbers)
  26. {
  27. int maxNum = numbers[0];
  28. int length = numbers.Length;
  29. for (int i = 0; i < length; i++)
  30. {
  31. if (length > 0)
  32. {
  33. if (numbers[i] > maxNum)
  34. {
  35. maxNum = numbers[i];
  36. }
  37. }
  38. else
  39. {
  40. return 0;
  41. }
  42. }
  43. return maxNum;
  44. }
  45.  
  46. static double Average(int sum, params int[] numbers)
  47. {
  48. int cnt = numbers.Length;
  49. return (double)sum / cnt;
  50. }
  51.  
  52. static int Sum(params int[] numbers)
  53. {
  54. int sum = 0;
  55. foreach (int number in numbers)
  56. {
  57. sum = sum + number;
  58. }
  59. return sum;
  60. }
  61.  
  62. static int Product(params int[] numbers)
  63. {
  64. int product = 1;
  65. foreach (int number in numbers)
  66. {
  67. product *= number;
  68. }
  69. return product;
  70. }
  71. static void Main()
  72. {
  73. Console.WriteLine("Minimum value in the set is: {0}", Minimum(1, 2, -4, 10,12));
  74. Console.WriteLine("Maximum value in the set is: {0}", Maximum(1, 2, -4, 10, 12));
  75. int sum = Sum(1, 2, -4, 10, 12);
  76. Console.WriteLine("Sum of the elements in the set is: {0}",sum );
  77. Console.WriteLine("Average of the elements in the set is: {0}", Average(sum, 1, 2, -4, 10, 12));
  78. Console.WriteLine("Product of the elements in the set is: {0}", Product(1, 2, -4, 10, 12));
  79.  
  80. /* Console.WriteLine("Minimum value in the set is: {0}", Minimum(0, 0, 0, 0, 0));
  81. Console.WriteLine("Maximum value in the set is: {0}", Maximum(0, 0, 0, 0, 0));
  82. int sum = Sum(0, 0, 0, 0, 0);
  83. Console.WriteLine("Sum of the elements in the set is: {0}", sum);
  84. Console.WriteLine("Average of the elements in the set is: {0}", Average(sum,0, 0, 0, 0, 0 ));
  85. Console.WriteLine("Product of the elements in the set is: {0}", Product(0, 0, 0, 0, 0));
  86. */
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment