Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.77 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Sub Main()
  4.         Dim c() As Double = {123, -45, 67, 8.7, 123.45, 455.56, 123.45, 455.56, 12.3, -10, 1.1}
  5.         Dim separator As String = "*************"
  6.         Console.WriteLine("Nasz ciąg to: {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", c(0), c(1), c(2), c(3), c(4), c(5), c(6), c(7), c(8), c(9), c(10))
  7.         Console.WriteLine(separator)
  8.         obliczfunkcje(c)
  9.         obliczsrednia(c)
  10.         Console.ReadKey()
  11.     End Sub
  12.     Public Function obliczfunkcje(ByVal x() As Double) As ArrayList
  13.         Dim suma As New ArrayList
  14.         Dim a As Double
  15.         Dim i As Integer
  16.         Dim separator As String = "**********"
  17.         For i = 0 To x.GetUpperBound(0)
  18.             If x(i) >= 5 Then
  19.                 a = Math.Sqrt(x(i) + 10)
  20.             Else
  21.                 a = (x(i) - 3) ^ 2
  22.             End If
  23.             suma.Add(a)
  24.         Next
  25.         For i = 0 To suma.Count - 1
  26.             Console.WriteLine("A więc nowa wartość dla {0} miejsca w ciągu to: {1}", i + 1, suma(i))
  27.         Next
  28.         Console.WriteLine(separator)
  29.         Return suma
  30.     End Function
  31.     Public Function obliczsrednia(ByVal y As Array) As Integer
  32.         Dim sredniatab As New ArrayList
  33.         Dim srednia As Integer
  34.         Dim liczba As Integer
  35.         Console.WriteLine("A teraz obliczymy średnią wartość ciągu !")
  36.         For i = 0 To y.GetUpperBound(0)
  37.             If y(i) > 0 Then
  38.                 sredniatab.Add(y(i))
  39.             End If
  40.         Next
  41.         liczba = sredniatab.Count
  42.         For i = 0 To sredniatab.Count - 1
  43.             srednia = srednia + sredniatab(i)
  44.         Next
  45.         srednia = srednia / liczba
  46.         Console.WriteLine("Nasza srednia wynosi: {0}", srednia)
  47.         Return srednia
  48.     End Function
  49.  
  50. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement