Download presentation
Presentation is loading. Please wait.
1
פתרון תרגיל 11
2
שאלה #1 Module Module1 Sub Main() Dim x(10, 10) As Integer Dim i, j As Integer For i = 1 To 10 For j = 1 To 10 x(i, j) = i * j Console.Write(" " & x(i, j)) Next Console.WriteLine() Next Console.ReadKey() End Sub End Module
3
שאלה #2 Module Module1 Sub Main() Dim x(3, 3) As Integer Dim i, j As Integer Dim num As New Random() Dim sum As Integer = 0 For i = 0 To 3 For j = 0 To 3 x(i, j) = num.Next(8, 14) If i = j Or (i + j) = 3 Then sum += x(i, j) End If Next Console.WriteLine("the sum is: " & sum) Console.ReadKey() End Sub End Module
4
שאלה #2 (כמעט זהה) Module Module1 Sub Main() Dim a(3, 3) As Integer Dim i, j, sam As Integer Dim num As New Random() sam = 0 For i = 0 To 3 For j = 0 To 3 a(i, j) = num.Next(8, 13) If i = j Then sam = sam + a(i, j) ElseIf i + j = 3 Then sam = sam + a(i, j) End If Next Console.WriteLine(sam) Console.ReadKey() End Sub End Module
5
שאלה 2 (איך שאני הייתי עושה) Module Module1 Sub Main() Dim sum1, sum2, i, j, x(3, 3) As Integer Dim r As New Random sum1 = 0 sum2 = 0 For i = 0 To 3 For j = 0 To 3 x(i, j) = r.Next(8, 13) Console.Write(x(i, j) & ",") Next Console.WriteLine() Next j = 4 For i = 0 To 3 sum1 += x(i, i) sum2 += x(i, j – i) Next Console.WriteLine("the sum is: " & sum1 + sum2) End Sub End Module
6
שאלה #3 Module Module1 Sub Main() Dim i, j, x(10, 5), y(10, 5) As Integer Dim r As New Random Dim b As Boolean b = True For i = 0 To 9 For j = 0 To 4 x(i, j) = r.Next(8, 18) y(i, j) = r.Next(3, 13) If x(i, j) <= y(i, j) Then b = False End If Next If b = True Then Console.WriteLine("yes") End If Console.ReadKey() End Sub End Module
7
פתרון יותר טוב? Module Module1 Sub Main() Dim a(4, 9), b(4, 9) As Integer Dim i, j, sam As Integer Dim num As New Random() sam = 0 For i = 0 To 4 For j = 0 To 9 a(i, j) = num.Next(8, 18) b(i, j) = num.Next(3, 13) If a(i, j) > b(i, j) Then sam = sam + 1 End If Next If sam = 50 Then Console.WriteLine("yes") End If Console.ReadKey() End Sub End Module
8
שאלה #4 Module Module1 Structure student Public name As String Public i_d As String Public average As Decimal End Structure Sub Main() Dim Pupile(4) As student Dim i As Integer Dim biggest As Decimal For i = 0 To 4 Console.WriteLine("please enter a name") Pupile(i).name = Console.ReadLine() Console.WriteLine("please enter an i d number") Pupile(i).i_d = Console.ReadLine() Console.WriteLine("please enter an average number") Pupile(i).average = Console.ReadLine() Next i = 0 biggest = Pupile(0).average For i = 0 To 4 If Pupile(i).average > biggest Then biggest = Pupile(i).average End If Next i = 0 For i = 0 To 4 If biggest = Pupile(i).average Then Console.WriteLine("the name of the student is: " & Pupile(i).name) End If Next Console.ReadKey() End Sub End Module
9
שאלה #4 Module Module1 Structure student Public name As String Public tz, memoza As Integer End Structure Sub Main() Dim sham(5) As student Dim i, j As Integer Dim n As String n = " " j = 0 For i = 1 To 5 Console.WriteLine("please enter the student name " & i) sham(i).name = Console.ReadLine Console.WriteLine("please enter the student i.d " & i) sham(i).tz = Console.ReadLine Console.WriteLine("please enter the student avrage " & i) sham(i).memoza = Console.ReadLine If sham(i).memoza > j Then j = sham(i).memoza n = sham(i).name End If Next Console.WriteLine("name: " & n & " tsiun is :" & j) Console.ReadKey() End Sub End Module
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.