1 / 13

תרגילים

תרגילים. גדול, קטן, וממוצע מקובץ. Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader _ (“z:<br>umbers.txt&quot;) Dim input As String

callia
Télécharger la présentation

תרגילים

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. תרגילים

  2. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader _ (“z:\numbers.txt") Dim input As String Dim t, i, big, num, small, avrage As Decimal i = 0 big = -999999999 small = 999999999 Do input = readnum.ReadLine() num = input If num > big Then big = num End If If num < small And num <> Nothing Then small = num End If If num <> 0 Then i += 1 t = t + num End If Loop Until input Is Nothing Dim writenum As StreamWriter = New StreamWriter _ (“z:\answersb.txt") avrage = t / (i) writenum.WriteLine("the largest number is " & big & "the smallest number is " & small & "the avrage of the numbers is " & avrage) writenum.Close() End Sub End Module

  3. גדול, קטן, וממוצע מקובץ יותר טוב Imports System.IO Module Module1 Sub Main() Dim fileReader As StreamReader fileReader = File.OpenText("z:\numbers.txt") Dim Input As String = "" Dim x, sum, big, small, c As Decimal Dim temp As Integer x = fileReader.ReadLine() sum = x big = x small = x c = 1 Do Until Input Is Nothing Input = fileReader.ReadLine() x = Input temp = Input sum += x If (x > big) Then big = x ElseIf ((x < small) And (x <> 0)) Then small = x End If c += 1 Loop Dim writer As StreamWriter = _ New StreamWriter("z:\answer.txt") writer.WriteLine("The small number is " & small & ".") writer.WriteLine("The big number is " & big & ".") writer.WriteLine("The average is " & sum / (c - 1) & ".") writer.Close() Console.ReadKey() End Sub End Module

  4. עצרת Module Module1 Sub Main() Dim i, x, mona AsInteger Console.WriteLine("enter number") x = Console.ReadLine If x < 0 Then Console.WriteLine("en azeret lemispar shlili") Else mona = 1 For i = 1 To x mona *= i Next EndIf Console.WriteLine("the azeret is: " & mona) Console.ReadKey() EndSub EndModule

  5. עצרת אחרת Module Module1 Sub Main() Dim x, input, atzeret AsDecimal Console.WriteLine("please enter a number") input = Console.ReadLine() atzeret = 1 For x = 1 To input atzeret = atzeret * x Next Console.WriteLine("the atzeret is "& atzeret) Console.ReadKey() EndSub EndModule

  6. עצרת שקשה לי להבין Module Module1 Sub Main() Dim x, i As Integer x = Console.ReadLine For i = 1 To x - 1 x = x * i Next Console.WriteLine(i & " aseret = " & x) Console.ReadKey() End Sub End Module

  7. Function Max Module Module1 Function Max(ByVal first AsInteger, ByVal second AsInteger, ByVal third AsInteger) AsInteger If first > second And first > third Then Return first ElseIf second > first And second > third Then Return second ElseIf third > first And third > second Then Return third EndIf EndFunction Sub Main() Dim x, y, z AsInteger Console.WriteLine("please enter 3 numberes") x = Console.ReadLine y = Console.ReadLine z = Console.ReadLine Console.WriteLine("the max num is " & Max(x, y, z)) Console.ReadKey() EndSub EndModule

  8. Function Max Module Module1 Function Max(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer Dim a, b As Integer a = (first + second) b = (third + second) If first > third Then If first > second Then Return first Else Return second End If Else If second > third Then Return second Else Return third End If End If End Function Sub Main() Dim x As Integer x = Max(6, 9, 1) Console.WriteLine(" the big number is: " & x) Console.ReadKey() End Sub End Module

  9. Function Max Module Module1 Function Max(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer Dim temp As Integer = first If second >= temp Then temp = second End If If third >= temp Then temp = third End If Return temp End Function Sub Main() Dim x, y, z As Integer Console.WriteLine("Please enter 3 numbers ") x = Console.ReadLine y = Console.ReadLine z = Console.ReadLine Console.WriteLine("Max:" & Max(x, y, z)) Console.ReadKey() End Sub End Module

  10. ציונים Module Module1 Function Grade(ByVal first AsDecimal) AsChar If first >= 90 Then Return“A" ElseIf first >= 80 Then Return“B" ElseIf first >= 70 Then Return“C" ElseIf first >= 60 Then Return“D" Else Return“F" EndIf EndFunction Sub Main() Dim x AsDecimal Console.WriteLine("na lirsom ziyon") x = Console.ReadLine Console.WriteLine("aziyon beotiyot: " & Grade(x)) Console.ReadKey() EndSub EndModule

  11. למה הMAIN פה בסדר? Module Module1 Function Grade(ByVal first AsDecimal) AsChar Dim ot AsChar If (first >= 60) And (first <= 69) Then ot = “D" ElseIf (first >= 90) And (first <= 100) Then ot = “A" ElseIf (first >= 80) And (first <= 89) Then ot = “B" ElseIf (first >= 70) And (first <= 79) Then ot = “C" ElseIf (first >= 0) And (first <= 59) Then ot = “F" EndIf Return ot EndFunction Sub Main() Console.WriteLine("the grade is :" & Grade(69)) Console.ReadKey() EndSub EndModule

  12. משוואה הריבועית Module Module1 Sub Mishva() Dim a, b, c AsInteger Console.WriteLine("na lirsom 3 misparim") a = Console.ReadLine b = Console.ReadLine c = Console.ReadLine If ((b * b) - (4 * (a * c))) > 0 Then Console.WriteLine("tsuba 1: " & (-b + ((b * b) - (4 * (a * c)))) / (2 * a)) Console.WriteLine("tsuba 2: " & (-b - ((b * b) - (4 * (a * c)))) / (2 * a)) Else Console.WriteLine("lo mugdar") EndIf EndSub Sub Main() Mishva() Console.ReadKey() EndSub EndModule

  13. משוואה הריבועית- פתרון יותר טוב Imports System.Math Module Module1 Sub Mishva() Dim a, b, c As Decimal Dim y, x1, x2 As Single Console.WriteLine("enter 3 number:") a = Console.ReadLine() b = Console.ReadLine() c = Console.ReadLine() y = ((b * b) - 4 * a * c) If (y >= 0) Then x1 = ((-b + Math.Sqrt(y)) / (2 * a)) x2 = ((-b - Math.Sqrt(y)) / (2 * a)) If (a <> 0) Then Console.WriteLine("the answer of x1 is: " & x1) Console.WriteLine("the answer of x2 is: " & x2) Else Console.WriteLine("eror") End If Else Console.WriteLine("eror") End If End Sub Sub Main() Mishva() Console.ReadKey() End Sub End Module

More Related