0% found this document useful (0 votes)
74 views12 pages

Rjeseni Zadaci

The document contains 19 code examples that demonstrate various programming concepts in Visual Basic such as: 1. Taking user input, performing calculations, and displaying output messages. 2. Checking for divisibility, primality, and perfect numbers. 3. Looping through arrays and lists, summing values, and finding minimums and maximums. 4. Comparing values, selecting output based on conditions, and calculating averages and factorials. The code snippets show how to write event handlers, use input and output boxes, perform basic math operations, and implement common programming logic using loops and conditional statements.

Uploaded by

siljeg.petar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views12 pages

Rjeseni Zadaci

The document contains 19 code examples that demonstrate various programming concepts in Visual Basic such as: 1. Taking user input, performing calculations, and displaying output messages. 2. Checking for divisibility, primality, and perfect numbers. 3. Looping through arrays and lists, summing values, and finding minimums and maximums. 4. Comparing values, selecting output based on conditions, and calculating averages and factorials. The code snippets show how to write event handlers, use input and output boxes, perform basic math operations, and implement common programming logic using loops and conditional statements.

Uploaded by

siljeg.petar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, i As Integer
n = InputBox("unesi broj n")
For i = 1 To n ^ 2
MsgBox(n ^ 3)
Next
End Sub
End Class

2.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, b, c As Integer
a = InputBox("unesite prvi broj")
b = InputBox("unesite drugi broj")
c = a + b
MsgBox(c)
End Sub
End Class

3.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, b, i As Integer
a = InputBox("unesi broj a")
b = InputBox("unesi broj b")
For i = 1 To a
If a Mod i = 0 And b Mod i = 0 Then
MsgBox(i)
End If
Next
End Sub
End Class
4.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, b, i As Integer
a = InputBox("unesi broj a")
b = InputBox("unesi broj b")
If b < 8 Then
MsgBox(((2 * a) + b) / (a + (2 * b)))
Else
For i = 1 To b
MsgBox(i)
Next
End If
End Sub
End Class

5.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, i As Integer
a = TextBox1.Text
If a = 1 Then
MsgBox("ponedjeljak")
ElseIf a = 2 Then
MsgBox("utorak")
ElseIf a = 3 Then
MsgBox("srijeda")
ElseIf a = 4 Then
MsgBox("cetvrtak")
ElseIf a = 5 Then
MsgBox("petak")
ElseIf a = 6 Then
MsgBox("subota")
ElseIf a = 7 Then
MsgBox("nedjelja")
Else
MsgBox("unijeli ste krivi broj")
End If

End Sub
End Class
6.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, t, p, i As Integer
n = InputBox("")
t = Math.Sqrt(n)
p = 1
For i = 2 To t
If n Mod i = 0 Then p = 0

Next
If p = 0 Then
MsgBox("broj nije prost")
Else
MsgBox("broj je prost")

End If
End Sub
End Class

7.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, p, t As Integer
n = InputBox("")
t = 1
p = 0
Do While t < n
t = 2 * t
p = p + 1
Loop
If t - n < n - t / 2 Then
MsgBox(t)
Else
MsgBox(t / 2)
End If

End Sub
End Class
8.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, s As Integer
n = InputBox("")
s = 0
Do While n > 0
s = s + n Mod 10
n = Int(n / 10)
Loop
MsgBox(s)

End Sub
End Class

9.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a(12)
Dim d1, m1, d2, m2, s, i As Integer
a(1) = 31
a(2) = 28
a(3) = 31
a(4) = 30
a(5) = 31
a(6) = 30
a(7) = 31
a(8) = 31
a(9) = 30
a(10) = 30
a(11) = 31
a(12) = 30
d1 = TextBox1.Text
m1 = TextBox2.Text
d2 = TextBox3.Text
m2 = TextBox4.Text
s = 0
For i = m1 To m2 - 1
s = s + a(i)
Next i
s = s + d2 - d1
MsgBox(s)
End Sub
End Class
10.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, s, i As Integer
s = 0
For i = 1 To 5
n = InputBox("")
If n < 0 Then
s = s + 1
End If
Next
MsgBox(s)

End Sub
End Class

11.

Public Class Form1


Dim a(100), i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
a(i) = TextBox1.Text
i = i + 1
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim j As Integer
For j = 0 To i - 1
If a(j) Mod 3 = 0 Then
ListBox2.Items.Add(a(j))
ElseIf a(j) Mod 7 = 0 Then
ListBox2.Items.Add(a(j))
End If
Next

End Sub
End Class
12.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, b, c, r As Integer
a = InputBox("unesi broj a")
b = InputBox("unesi broj b")
c = InputBox("unesi broj c")
If a > b And a > c Then
r = a - (b + c)
ElseIf b > a And b > c Then
r = b - (a + c)
Else : r = c - (a + b)
End If
MsgBox(r)

End Sub
End Class

13.

Public Class Form1


Dim a(100), b(100), suma, i As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
a(i) = TextBox1.Text
b(i) = TextBox2.Text
i = i + 1
ListBox1.Items.Add(TextBox1.Text)
ListBox1.Items.Add(TextBox2.Text)
Dim j As Integer
For j = a(j) To b(j)
If j Mod 2 = 0 Then
suma = suma + j
TextBox3.Text = suma
End If
Next

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ListBox1.Items.Clear()
i = 0
suma = 0
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles TextBox2.TextChanged
5:
End Sub
End Class
14.
Public Class Form1
Dim a(100), i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
a(i) = TextBox1.Text
Dim j As Integer
j = j + 1
For j = 2 To 9
If a(i) Mod j = 0 Then
ListBox1.Items.add(j)
End If
Next

End Sub
End Class

15.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, s, i As Integer
n = TextBox1.Text
For i = 1 To n
If n Mod i = 0 Then
ListBox1.Items.Add(i)
s = s + i
End If
Next i
If s = 2 * n Then
MsgBox("broj je savren")
Else
MsgBox("Broj nije savren")
End If
End Sub
End Class
16.
Public Class Form1
Dim i, zbroj As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim n As Integer
n = TextBox1.Text
zbroj = zbroj + n
i = i + 1
TextBox2.Text = i
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim sredina As Double
sredina = zbroj / i
TextBox3.Text = sredina
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
i = 0
zbroj = 0
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
End Class

17.

Public Class Form1


Dim a(100), b(100), i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
a(i) = TextBox1.Text
b(i) = TextBox2.Text
ListBox1.Items.Add(a(i) + b(i))
ListBox1.Items.Add(a(i) * b(i))
i = i + 1
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim j As Integer
For j = (a(j) + b(j)) To (a(j) * b(j))
If j Mod 2 = 0 Then
ListBox2.Items.Add(j)
End If
Next
End Sub
End Class
18.

Public Class Form1


Dim faktorijel, zbroj As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim n, i As Integer
n = TextBox1.Text
textbox1.text = ""
If n < 10 Then
listbox1.items.add(n)
faktorijel = 1
For i = 1 To n
faktorijel = faktorijel * i
Next
zbroj = zbroj + faktorijel
End If
TextBox2.text = zbroj
End Sub
End Class

19.

Public Class Form1


Dim a(100), min, max, i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
i = i + 1
a(i) = TextBox1.Text
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim j As Integer
min = a(1)
max = a(1)
For j = 1 To i
If a(j) < min Then
min = a(j)
ElseIf a(j) > max Then
max = a(j)
End If
Next j
ListBox2.Items.Add(min)
ListBox2.Items.Add(max)
End Sub
End Class
20.

Public Class Form1


Dim a(100), b(100), i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
i = i + 1
a(i) = textbox1.text
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim j As Integer
For j = 1 To i
b(j) = a(i - j + 1)
ListBox2.Items.Add(b(j))
Next
End Sub
End Class

21.
Public Class Form1
Dim a(100), min, max, i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
i = i + 1
a(i) = textbox1.text
listbox1.items.add(textbox1.text)
textbox1.text = ""
textbox1.focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim j As Integer
min = a(1)
max = a(1)
For j = 1 To i
If a(j) < min Then
min = a(j)
ElseIf a(j) > max Then
max = a(j)
End If
Next j
listbox2.items.add(min)
ListBox2.Items.Add(max)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Dim razlika As Integer
razlika = max - min
razlika = MsgBox(razlika)
End Sub
End Class
22.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, i As Integer
Do
n = InputBox("")
If n Mod 5 = 0 Then
i = i + n
End If
Loop While n <> 42
MsgBox(i)
End Sub
End Class

23.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, i, j, poz, neg, nula As Integer
Dim a(100, 100) As Integer
n = InputBox("unijeti broj redaka i stupaca kvadratne matrice")
For i = 1 To n
For j = 1 To n
a(i, j) = InputBox("unijeti broj za element u" + CStr(i) +
"retku" + CStr(j) + "stupcu")
ListBox1.Items.Add(CStr(i) + "." + CStr(j) + "=" +
CStr(a(i, j)))
If a(i, j) > 0 Then
poz = poz + 1
ElseIf a(i, j) < 0 Then
neg = neg + 1
Else
nula = nula + 1
End If
Next j
Next i
TextBox1.Text = poz
TextBox2.Text = neg
TextBox3.Text = nula
End Sub
End Class

BLIC-1

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, i As Integer
n = TextBox1.Text
For i = 1 To n Step 2
ListBox1.Items.Add(i)
Next
End Sub
End Class
BLIC-2

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim m, n, i As Integer
n = InputBox("")
m = InputBox("")
For i = 1 To n
If m Mod i <> 0 Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class

BLIC-3

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim n, i, zbroj As Integer
n = InputBox("")
For i = 1 To n
If i Mod 2 <> 0 Then
ListBox1.Items.Add(i)
zbroj = zbroj + i
End If
MsgBox(zbroj)
Next
End Sub

End Class

You might also like