190 likes | 373 Views
محاضرات في البرمجة. المحاضرة الرابعة. القسم العملي. للمزيد زورونا على موقعنا الإلكتروني:. CivTeam.wordpress.com. الحلقات for. For i =1 To x step -2 …………. …………. Next. الحلقة Do while. DO while ( شرط ) …………. …………. Loop DO …………. ………….
E N D
محاضرات في البرمجة المحاضرة الرابعة القسم العملي للمزيد زورونا على موقعنا الإلكتروني: CivTeam.wordpress.com
الحلقات for For i =1 To x step -2 …………. …………. Next
الحلقة Do while DO while (شرط) …………. …………. Loop DO …………. …………. Loop while (شرط)
Imports System.Console Module Sum1 Sub Main() Dim Sum, num As Double Sum = 0 WriteLine("Enter a positive number ") num = ReadLine() Do While (num > 0) Sum = Sum + num WriteLine("Enter another positive number ") num = ReadLine() Loop WriteLine("Sum= " & Sum) End Sub End Module
Imports System.Console Module Sum2 Sub Main() Dim Sum, num As Double Sum = 0 Do WriteLine("Enter a positive number ") num = ReadLine() If (num > 0) Then Sum = Sum + num End If Loop While (num > 0) WriteLine("Sum= " & Sum) End Sub End Module
Imports System.Console Module insist Sub Main() Dim x As Integer Do WriteLine("Enter a value larger than 0") x = ReadLine() Loop While (x <= 0) End Sub End Module
PI PI/4 = 1/1 - 1/3 + 1/5 - 1/7 + ... PI = 4/1 - 4/3 + 4/5 - 4/7 + ...
Imports System.Console Imports System.Math Module MyPI Sub Main() Dim p, part, res As Double Dim i, n As Integer Write("How many digits after decimal point: ") n = ReadLine() res = 1.0 / (10 ^ (n + 1)) i = 1 p = 0 part = 4 Do While (Abs(part) > res) p = p + part i = i + 2
If (part > 0) Then part = -4 / i Else part = 4 / i End If Loop WriteLine("My PI= " & p) WriteLine("VB PI= " & PI) End Sub End Module
الحلقة while Sub Main() Dim cnt As Int16 = 1 Dim x As Int32 Dim xf As Int32 = 1 Console.WriteLine("Enter x") x = Console.ReadLine While cnt < x cnt = cnt +1 xf = xf * cnt End While Console.WriteLine(xf) Console.ReadLine() End Sub
Imports System.Console Imports System.math Module Module1 Sub Main() Dim tt As Integer WriteLine("integer(Rang)={0} to {1}", tt.MaxValue, tt.MinValue) 'WriteLine("integer(min)={0}", tt.MinValue) WriteLine(Sqrt(9)) ReadLine() End Sub End Module
مسائل في البرمجة مسألة أكتب برنامجاً يقوم بحساب المساحة و المحيط للأشكال الهندسية ( المستطيل، المربع، المثلث، الدائرة)
مسائل في البرمجة Imports System.Math Imports System. Console Module Module1 Sub Main() Dim wrng As Boolean Dim shp As String Dim a, c As Single str: WriteLine("Press 'r' for rectangle") WriteLine("or 's' for square") WriteLine("or 't' for triangle") WriteLine("or 'c' for circle") shp = ReadLine wrng = False
مسائل في البرمجة Select Case shp Case "r" Dim l, w As Single WriteLine("Enter the length") l = ReadLine WriteLine("Enter the width") w = ReadLine a = l * w c = 2 * (l + w)
مسائل في البرمجة Case "s" Dim s As Single WriteLine("Enter the side") s = ReadLine a = s ^ 2 c = 4 * s
مسائل في البرمجة Case "t" Dim s1, s2, s3, b, h As Single WriteLine("Enter the first side") s1 = ReadLine WriteLine("Enter the second side") s2 = ReadLine WriteLine("Enter the third side") s3 = ReadLine WriteLine("Enter the base") b = ReadLine WriteLine("Enter the height") h = ReadLine a = (b * h) / 2 c = s1 + s2 + s3
مسائل في البرمجة Case "c" Dim r As Single WriteLine("Enter the radius") r = ReadLine a = pi * r ^ 2 c = 2 * PI * r Case Else wrng = True WriteLine("Wrong selection") GoTo str End Select If Not wrng Then WriteLine("Area= " & a) WriteLine("Circumference= " & c) End If
مسائل في البرمجة WriteLine("Press 'r' to return or 'x' to exit") Dim st As String st = ReadLine If st = "r" Then GoTo str ElseIf st = "x" Then Exit Sub End If End Sub End Module