Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Шпоры по задачам.docx
Скачиваний:
2
Добавлен:
27.10.2018
Размер:
37.36 Кб
Скачать

21. Числа Фибоначи

Function Fk(ByVal n As Integer) As Integer

If (n = 1) Or (n = 2) Then

Fk = 1

Else : Fk = Fk(n - 1) + Fk(n - 2)

End If

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim n, r As Integer

n = Val(TextBox1.Text)

If n < 100 Then

r = Fk(n)

TextBox2.Text = Str(r)

Else : MessageBox.Show("Введите меньшее n")

End If

End Sub

22. Отриц. Элем. Массива и их индексы.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim n, i As Integer

n = Val(TextBox1.Text)

Dim A(n) As Integer

Dim Rnd = New Random()

ListBox1.Items.Clear()

For i = 0 To n - 1

A(i) = Rnd.Next(31) - 15

ListBox1.Items.Add(Convert.ToString(A(i)))

Next i

Dim count As Integer = 0

For i = 0 To n - 1

If A(i) < 0 Then

count = count + 1

ListBox2.Items.Add(Convert.ToString(i))

End If

Next i

ListBox2.Items.Add("Всего отрицатиельных элем. =" & Convert.ToString(count))

End Sub

23.Число соседств в массиве.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim M() As Integer = {-5, 12, 44, -6, -8, -9, 56, 32, 12, 65, -45, 98, -2}

Dim count As Integer = 0

Dim i As Int16

For i = 0 To 11

If M(i) * M(i + 1) < 0 Then

count = count + 1

End If

Next i

ListBox2.Items.Add(Convert.ToString(count))

End Sub

25. График астроиды.

Imports System

Imports System.Windows.Forms

Imports System.Drawing

Imports System.IO

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Dim k As Integer

Dim r As Double

k = Val(TextBox1.Text)

Dim pB2 As Graphics

pB2 = PictureBox1.CreateGraphics()

pB2.Clear(Color.Blue)

Dim X0 As Integer = PictureBox1.Width / 2

Dim Y0 As Integer = PictureBox1.Height / 2

Dim penGraph As New Pen(Color.Red)

Dim X1, Y1, X2, Y2 As Integer

Dim a As Integer, ar, L, X, Y As Single

Dim R1 As Integer = 40

X1 = X0 + k

Y1 = Y0

For a = 1 To 360

ar = a * Math.PI / 180

r = Math.Cos(ar) ^ 2

X2 = X0 + k * r * Math.Cos(ar)

Y2 = Y0 - k * r * Math.Sin(ar)

pB2.DrawLine(penGraph, X1, Y1, X2, Y2)

X1 = X2

Y1 = Y2

Next

End Sub

26. Мухоморчики до края картинки.

Imports System

Imports System.Windows.Forms

Imports System.Drawing

Imports System.IO

Sub Mashroom(ByVal x As Integer, ByVal y As Integer, ByVal picG As Graphics, ByVal PenDraw As Pen)

picG = PictureBox1.CreateGraphics()

picG.DrawEllipse(Pens.Black, x, y, 10, 20)

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

Dim pB3 As Graphics

pB3 = PictureBox1.CreateGraphics()

pB3.Clear(Color.White)

Dim x, y As Integer

x = 0

y = 30

Do While x < PictureBox1.Width - 10

Mashroom(x, y, pB3, Pens.Aqua)

x = x + 20

Loop

End Sub

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]