Фотоистории /
bad sector v.1.0.1.4 (empty green version)
07.08.2011
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 610 , 987 , 1597 , 2584 , 4181 , 6765 ,
Moscow2008-2010 Moscow2008-2010
DIM F(16) F(1) = 1 F(2) = 1 FOR i = 3 TO 16: F(i) = F(i - 1) + F(i - 2) NEXT i DIM S AS STRING S = "" FOR i = 1 TO 16: S = S + STR$(F(i)) + ", " NEXT i S = S + "..." PRINT SModule Module1 Sub Main() Dim A, B, C, D As Integer Dim p1, p2 As Double Try Console.Write("A = ") A = Val(Console.ReadLine()) Console.Write("B = ") B = Val(Console.ReadLine()) Console.Write("C = ") C = Val(Console.ReadLine()) Catch ex As Exception Console.WriteLine("Invalid input.") Return End Try If A = 0 Then Console.WriteLine("Not a quadratic equation.") Return End If D = B * B - 4 * A * C p1 = -B / 2.0 / A p2 = Math.Sqrt(Math.Abs(D)) / 2.0 / A If D = 0 Then Console.Write("x = " & p1.ToString()) ElseIf D > 0 Then Console.WriteLine("x1 = " & (p1 + p2).ToString()) Console.WriteLine("x2 = " & (p1 - p2).ToString()) Else Console.WriteLine("x1 = (" & p1.ToString() & "," & p2.ToString() & ")") Console.WriteLine("x2 = (" & p1.ToString() & ",-" & p2.ToString() & ")") End If End Sub End ModuleOption Explicit Declare Function AllocConsole Lib "kernel32" () As Long Declare Function FreeConsole Lib "kernel32" () As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _ (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _ nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _ lpReserved As Any) As Long Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) As Long Public Function Fibonacci(ByVal n As Integer) As Integer If (n <= 2) Then Fibonacci = 1 Else Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2) End If End Function Private Sub Main() 'create a console instance AllocConsole 'get handle of console output Dim hOut As Long hOut = GetStdHandle(-11&) 'output string to console output Dim s As String Dim i As Integer For i = 1 To 16 Step 1 s = Fibonacci(i) & ", " WriteConsole hOut, ByVal s, Len(s), vbNull, vbNull Next i s = "..." & vbCrLf WriteConsole hOut, ByVal s, Len(s), vbNull, vbNull 'make a pause to look at the output Sleep 2000 'close the handle and destroy the console CloseHandle hOut FreeConsole End SubModule Module1 Function Fibonacci(ByVal n As Integer) As Long If n < 3 Then Return 1 Else Return Fibonacci(n - 1) + Fibonacci(n - 2) End If End Function Sub Main() For i As Integer = 1 To 16 Console.Write(Fibonacci(i) & ", ") Next Console.WriteLine("...") End Sub End ModuleDIM f AS LONG f = 1 PRINT " 0 ! ="; f FOR i = 1 TO 16: f = f * i: PRINT i; "! ="; f NEXT i END
|