Presentation is loading. Please wait.

Presentation is loading. Please wait.

تعريف المصفوفات Arrays Dim OneDim (9) As Integer ' 10 عناصر Dim TwoDims (1, 1) As String ' عناصر 4= 2 * 2 OneDim (0) = 100 OneDim (1) = 200 … OneDim (9)

Similar presentations


Presentation on theme: "تعريف المصفوفات Arrays Dim OneDim (9) As Integer ' 10 عناصر Dim TwoDims (1, 1) As String ' عناصر 4= 2 * 2 OneDim (0) = 100 OneDim (1) = 200 … OneDim (9)"— Presentation transcript:

1

2 تعريف المصفوفات Arrays Dim OneDim (9) As Integer ' 10 عناصر Dim TwoDims (1, 1) As String ' عناصر 4= 2 * 2 OneDim (0) = 100 OneDim (1) = 200 … OneDim (9) = 900 TwoDims (0, 0) = “Ahmad” TwoDims (0, 1) = “khaled” TwoDims (1, 0) = “Mouhamed” TwoDims (1, 1) = “Hassan”

3 Imports system.console Module Module1 sub Main() Dim OneDim() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9} Dim TwoDims(,) As String = {{“Saad",”George"},{”Lolo",”ٌReem"}} Dim test(,) as Integer = {{1,2,3},{4,5,6}} Writeline(test(0,0)) Writeline(test(0,1)) Writeline(test(0,2)) Writeline(test(1,0)) Writeline(test(1,1)) Writeline(test(1,2)) Readline() End sub

4 Imports System.Console Module Module1 Sub Main() Dim liste() As String = {"Rami", "Sami", "Keis", "Lina", "Linda"} Dim points() As Integer = {70, 65, 66, 50, 55} WriteLine(liste.Length) WriteLine(liste.Rank) WriteLine(liste(0)) WriteLine(liste(2) & " : " & points(2)) ReadLine() End Sub End Module

5 مسألة أكتب برنامجاً يقوم بقراءة ثلاثة أعداد {a1, a2, a3} و يحسب قيمة كل من المتوسط الحسابي و المدى لتلك الأعداد و يظهرهما على الشاشة مسائل في البرمجة

6 Sub Main() Dim a(2), m, rng As Single Dim minv, maxv As Single Console.WriteLine("Enter the first number") a(0) = Console.ReadLine Console.WriteLine("Enter the second number") a(1) = Console.ReadLine Console.WriteLine("Enter the third number") a(2) = Console.ReadLine m = (a(0) + a(1) + a(2)) / 3 مسائل في البرمجة

7 If a(0) > a(1) And a(0) > a(2) Then maxv = a(0) ElseIf a(1) > a(0) And a(1) > a(2) Then maxv = a(1) Else maxv = a(2) End If If a(0) < a(1) And a(0) < a(2) Then minv = a(0) ElseIf a(1) < a(0) And a(1) < a(2) Then minv = a(1) Else minv = a(2) End If مسائل في البرمجة

8 rng = maxv - minv Console.WriteLine("The Avarage is: " & m) Console.WriteLine("The range is: " & rng) Console.WriteLine("Press any key to exit") Console.ReadLine() End Sub مسائل في البرمجة

9 If a(1) > a(2) Then If a(3) > a(1) Then minv = a(2) : maxv = a(3) ElseIf a(3) < a(2) Then minv = a(3) : maxv = a(1) Else minv = a(2) : maxv = a(1) End If Else If a(3) > a(2) Then minv = a(1) : maxv = a(3) ElseIf a(3) < a(1) Then minv = a(3) : maxv = a(2) Else minv = a(1) : maxv = a(2) End If مسائل في البرمجة

10 مسألة أكتب برنامجاً يقوم بقراءة مجموعة من الأعداد {a1, … an} عددها n و يحسب قيمة كل من المتوسط الحسابي و المدى لتلك الأعداد و يظهرهما على الشاشة مسائل في البرمجة

11 Sub Main() Dim n As Int16 Dim a(), sum, m, rng As Single Console.WriteLine("Enter the number of the elements") n = Console.ReadLine ReDim a(n) Console.WriteLine("Enter the first number") a(0) = Console.ReadLine Dim minv As Single = a(0) Dim maxv As Single = a(0) sum = a(0) For i As Int16 = 1 To n-1 Console.WriteLine("Enter the next number") a(i) = Console.ReadLine sum += a(i) If a(i) < minv Then minv = a(i) If a(i) > maxv Then maxv = a(i) Next m = sum / n rng = maxv - minv Console.WriteLine("The Avarage is: " & m) Console.WriteLine("The range is: " & rng) Console.WriteLine("Press any key to exit") Console.ReadLine() End Sub مسائل في البرمجة

12 مسألة أكتب برنامجاً يقوم بحساب البعد بين نقطتين و من ثم حساب ميل المستقيم المحدد بهما مسائل في البرمجة

13 Imports System.Math Module Module1 Sub Main() strt: Dim st As String Dim x1, x2, y1, y2, dis, slope As Single Console.WriteLine("Enter x1") x1 = Console.ReadLine Console.WriteLine("Enter y1") y1 = Console.ReadLine Console.WriteLine("Enter x2") x2 = Console.ReadLine Console.WriteLine("Enter y2") y2 = Console.ReadLine dis = Sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) مسائل في البرمجة

14 If dis > 0 Then If x1 <> x2 Then slope = (y1 - y2) / (x1 - x2) Console.WriteLine("Slpoe= " & slope) Else Console.WriteLine("Undefined slope") End If Else Console.WriteLine("You entered two congruant points") End If Console.WriteLine("Press x to exit or r to repeat the program with new points") st = Console.ReadLine If st = "r" Then GoTo strt ElseIf st = "x" Then Exit Sub End If End Sub End Module مسائل في البرمجة

15 مسألة لدينا مصفوفة من الدرجة الثانية تحوي عدد من العناصر و قيمة ما نريد إخراج مصفوفة مماثلة في الأبعاد للمصفوفة الأصلية و تحوي واحدات في المواقع المقابلة لوجود القيمة المعطاة و أصفار في بقية المواقع مسائل في البرمجة

16 Sub Main() Dim v As Single Dim b(,), e(,) As Single Dim n, m As Int16 Console.WriteLine("Enter the number of rows") m = Console.ReadLine Console.WriteLine("Enter the number of columns") n = Console.ReadLine ReDim b(m, n) : ReDim e(m, n) مسائل في البرمجة

17 'reading the data For i As Int16 = 1 To m For j As Int16 = 1 To n Console.WriteLine("Enter the element b(" & i & "," & j & ")") b(i, j) = Console.ReadLine Next Console.WriteLine("Enter the value you want to search for") v = Console.ReadLine مسائل في البرمجة

18 'searching for the value For i As Int16 = 1 To m For j As Int16 = 1 To n If b(i, j) = v Then e(i, j) = 1 Else e(i, j) = 0 End If Next مسائل في البرمجة

19 'printing the matrix e For i As Int16 = 1 To m For j As Int16 = 1 To n Console.WriteLine("e(" & i & "," & j & ")= " & e(i, j)) Next Console.WriteLine() مسائل في البرمجة

20 'another way to print the matrix e Dim ee As String Dim k, l As Int16 Console.WriteLine("e=") Console.WriteLine() For k = 1 To m ee = "" For l = 1 To n ee &= e(k, l) & " " Next Console.WriteLine(ee) Next Console.ReadLine() End Sub مسائل في البرمجة

21 مسألة لدينا مجموعة نقط في المستوي n نقطة و مستقيم و المطلوب إيجاد بعد كل نقطة عن ذلك المستقيم مسائل في البرمجة

22 Imports System.Console Imports System.Math Module Module1 Sub Main() str: Dim st As String Dim a, b, c As Single Dim p(,), d() As Single Dim n As Int16 WriteLine("Enter the number of points") n = ReadLine() ReDim p(n, 2) : ReDim d(n) مسائل في البرمجة

23 WriteLine("Enter the constant a") a = ReadLine() WriteLine("Enter the constant b") b = ReadLine() WriteLine("Enter the constant c") c = ReadLine() If a = 0 And b = 0 Then WriteLine("No line with a=0 and b=0") ReadLine() Exit Sub End If مسائل في البرمجة

24 For i As Int16 = 1 To n WriteLine("Enter x(" & i & ")") p(i, 1) = ReadLine() WriteLine("Enter y(" & i & ")") p(i, 2) = ReadLine() Next For i As Int16 = 1 To n d(i) = Abs(a * p(i, 1) + b * p(i, 2) + c) / Sqrt(a ^ 2 + b ^ 2) WriteLine("P(" & p(i, 1) & "," & p(i, 2) & ") -- distance= " & d(i)) Next WriteLine("Press 'r' to repeat") st = ReadLine() If st = "r" Then GoTo str End Sub End Module مسائل في البرمجة


Download ppt "تعريف المصفوفات Arrays Dim OneDim (9) As Integer ' 10 عناصر Dim TwoDims (1, 1) As String ' عناصر 4= 2 * 2 OneDim (0) = 100 OneDim (1) = 200 … OneDim (9)"

Similar presentations


Ads by Google