big) Then big = x ElseIf ((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"> big) Then big = x ElseIf ((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">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader.

Similar presentations


Presentation on theme: "תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader."— 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 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 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 As Integer 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 End If Console.WriteLine("the azeret is: " & mona) Console.ReadKey() End Sub End Module

5 עצרת אחרת Module Module1 Sub Main() Dim x, input, atzeret As Decimal 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() End Sub End Module

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 As Integer, ByVal second As Integer, ByVal third As Integer) As Integer 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 End If End Function Sub Main() Dim x, y, z As Integer 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() End Sub End Module

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 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 As Decimal) As Char 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" End If End Function Sub Main() Dim x As Decimal Console.WriteLine("na lirsom ziyon") x = Console.ReadLine Console.WriteLine("aziyon beotiyot: " & Grade(x)) Console.ReadKey() End Sub End Module

11 למה ה MAIN פה בסדר ? Module Module1 Function Grade(ByVal first As Decimal) As Char Dim ot As Char 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" End If Return ot End Function Sub Main() Console.WriteLine("the grade is :" & Grade(69)) Console.ReadKey() End Sub End Module

12 משוואה הריבועית Module Module1 Sub Mishva() Dim a, b, c As Integer 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") End If End Sub Sub Main() Mishva() Console.ReadKey() End Sub End Module

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


Download ppt "תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader."

Similar presentations


Ads by Google