Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,22 @@
|
|||
require "io2"
|
||||
local fmt = require "fmt"
|
||||
|
||||
local f = |x| -> math.sqrt(math.abs(x)) + 5 * x * x * x
|
||||
|
||||
local s = {}
|
||||
print("Please enter 11 numbers:")
|
||||
local count = 0
|
||||
repeat
|
||||
s[++count] = io.readNum(string.format(" Number %-2d : ", count))
|
||||
until count == 11
|
||||
|
||||
s:reverse()
|
||||
print("\nResults:")
|
||||
for s as item do
|
||||
local fi = f(item)
|
||||
if fi <= 400 then
|
||||
fmt.print(" f(%6.3f) = %7.3f", item, fi)
|
||||
else
|
||||
fmt.print(" f(%6.3f) = overflow", item)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
:- use_module(library(dcg/basics)).
|
||||
:- use_module(library(dcg/high_order)).
|
||||
|
||||
main :-
|
||||
% ask for 11 numbers to be read into a sequence S
|
||||
format("Enter 11 numbers for evaluation~n", []),
|
||||
length(S, 11),
|
||||
phrase_from_stream((sequence(integer, "\n", S), remainder(_)), user_input),
|
||||
|
||||
% reverse sequence S
|
||||
reverse(S, ReversedS),
|
||||
|
||||
% for each item in sequence S
|
||||
foreach((
|
||||
member(Item, ReversedS),
|
||||
% result := call a function to do an operation
|
||||
Result is sqrt(abs(Item)) + 5 * Item ^ 3
|
||||
),
|
||||
% if result overflows
|
||||
( Result > 400
|
||||
% alert user
|
||||
-> format("~d: OVERFLOW~n", [Item])
|
||||
% else print result
|
||||
; format("~d: ~f~n", [Item, Result])
|
||||
)
|
||||
).
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
Dim s(1 To 11) As Double
|
||||
Dim x As Double
|
||||
Dim i As Integer
|
||||
|
||||
Print "enter 11 numbers"
|
||||
For i = 1 To 11
|
||||
Print i; " => ";
|
||||
Input s(i)
|
||||
Next i
|
||||
|
||||
Print: Print String$(20, "-")
|
||||
|
||||
For i = 11 To 1 Step -1
|
||||
x = f(s(i))
|
||||
Print "f("; s(i); ") = ";
|
||||
If x > 400 Then
|
||||
Print "-=< overflow >=-"
|
||||
Else
|
||||
Print x
|
||||
End If
|
||||
Next i
|
||||
End
|
||||
|
||||
Function f (n As Double)
|
||||
f = Sqr(Abs(n)) + 5 * n ^ 3
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue