Sub Main Dim x9 As Integer Dim i

  • Slides: 8
Download presentation

 חישוב סכום המספרים וכן מציאת מקסימום במערך Sub Main() Dim x(9) As Integer

חישוב סכום המספרים וכן מציאת מקסימום במערך Sub Main() Dim x(9) As Integer Dim i As Integer For i = 0 To 9 x(i) = Console. Read. Line() Next Dim sum As Integer = 0 Dim max = x(0) For i = 0 To 9 sum += x(i) If (x(i) > max) Then max = x(i) End If Next Console. Write. Line (“Sum is {0} and Max is {1} ", sum, max) End Sub

 Structure Member Dim name As String Dim phone As String Dim age As

Structure Member Dim name As String Dim phone As String Dim age As Integer End Structure Sub Main() Dim x(4) As Member , ( ומערך structure ) מבנה מציאת ערך מינימלי והדפסתו For i = 0 To x. Length - 1 x(i). name = Console. Read. Line() x(i). phone = Console. Read. Line() x(i). age = Console. Read. Line() Next Dim min As Integer = 120, Dim n As String = "" For i = 0 To x. Length - 1 If x(i). age < min Then min = x(i). age n = x(i). name End If Next Console. Write. Line("youngest age is: " & min & " youngest name is: " & n) End Sub

 Sub gen. Rand(By. Ref x, By. Val low, By. Val high) Dim i,

Sub gen. Rand(By. Ref x, By. Val low, By. Val high) Dim i, j As Integer מילוי מערך דו ממדי במספרים אקראיים והדפסתם For i = 0 To 9 For j = 0 To 9 x(i, j) = Int((high - low + 1) * Rnd() + low) Next End Sub Print. Arr(By. Val x) Dim i, j As Integer For i = 0 To 9 Console. Write("Row " & i & ": ") For j = 0 To 9 Console. Write(" " & x(i, j) & " ") Next Console. Write. Line() Next End Sub

 Sub Main() Dim a(9, 9) As Integer Randomize() gen. Rand(a, 1, 10) Console.

Sub Main() Dim a(9, 9) As Integer Randomize() gen. Rand(a, 1, 10) Console. Write. Line("1 to 10") Print. Arr(a) gen. Rand(a, 5, 10) Console. Write. Line("5 to 10") Print. Arr(a) gen. Rand(a, 3, 8) Console. Write. Line("3 to 8") Print. Arr(a) End Sub . . . המשך

Dim b As Boolean b = False Console. Write. Line("False b is: " &

Dim b As Boolean b = False Console. Write. Line("False b is: " & b) b = True Console. Write. Line("True b is: " & b) b = 0 Console. Write. Line("0 b is: " & b) b = 1 Console. Write. Line("1 b is: " & b) b = 2 Console. Write. Line("2 b is: " & b) b = -1 Console. Write. Line("-1 b is: " & b) משתנה בוליאני שמקבל מספר true <> 0 , false =0

Imports System. IO Module 1 Sub Main() קבצים Dim Input As Integer = 0,

Imports System. IO Module 1 Sub Main() קבצים Dim Input As Integer = 0, sum As Integer = 0 Dim o As Stream. Reader Dim c As Stream. Writer o = File. Open. Text("C: myfile. txt") While Input <> -1 Input = o. Read. Line() sum += Input End While Console. Write. Line(sum) c = My. Computer. File. System. Open. Text. File. Writer("C: my. Outfile. txt", True) c. Write. Line("the sum is: " & sum) c. Close() ' without close, doesnt write. Console. Read. Key() End Sub End Module