Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,13 @@
|
|||
(defun read-numbers ()
|
||||
(princ "Enter 11 numbers (space-separated): ")
|
||||
(let ((numbers '()))
|
||||
(dotimes (i 11 numbers)
|
||||
(push (read) numbers))))
|
||||
|
||||
(defun trabb-pardo-knuth (func overflowp)
|
||||
(let ((S (read-numbers)))
|
||||
(format T "~{~a~%~}"
|
||||
(substitute-if "Overflow!" overflowp (mapcar func S)))))
|
||||
|
||||
(trabb-pardo-knuth (lambda (x) (+ (expt (abs x) 0.5) (* 5 (expt x 3))))
|
||||
(lambda (x) (> x 400)))
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
program tpk
|
||||
implicit none
|
||||
|
||||
real, parameter :: overflow = 400.0
|
||||
real :: a(11), res
|
||||
integer :: i
|
||||
|
||||
write(*,*) "Input eleven numbers:"
|
||||
read(*,*) a
|
||||
|
||||
a = a(11:1:-1)
|
||||
do i = 1, 11
|
||||
res = f(a(i))
|
||||
write(*, "(a, f0.3, a)", advance = "no") "f(", a(i), ") = "
|
||||
if(res > overflow) then
|
||||
write(*, "(a)") "overflow!"
|
||||
else
|
||||
write(*, "(f0.3)") res
|
||||
end if
|
||||
end do
|
||||
|
||||
contains
|
||||
|
||||
real function f(x)
|
||||
real, intent(in) :: x
|
||||
|
||||
f = sqrt(abs(x)) + 5.0*x**3
|
||||
|
||||
end function
|
||||
end program
|
||||
|
|
@ -1,16 +1,5 @@
|
|||
f(x) = abs(x)^.5 + 5x^3
|
||||
for i in map(parse_int,reverse(split(chomp(readline(STDIN)),' ')))
|
||||
println("$i: ",f(i)>400?"TOO LARGE":f(i))
|
||||
for i in map(parseint,reverse(split(readline())))
|
||||
v = f(i)
|
||||
println("$i: ", v > 400 ? "TOO LARGE" : v)
|
||||
end
|
||||
1 2 3 4 5 6 7 8 9 10 11
|
||||
11: TOO LARGE
|
||||
10: TOO LARGE
|
||||
9: TOO LARGE
|
||||
8: TOO LARGE
|
||||
7: TOO LARGE
|
||||
6: TOO LARGE
|
||||
5: TOO LARGE
|
||||
4: 322.0
|
||||
3: 136.73205080756887
|
||||
2: 41.41421356237309
|
||||
1: 6.0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
numbers=RandomReal[{-2,6},11]
|
||||
tpk[numbers_,overflowVal_]:=Module[{revNumbers},
|
||||
revNumbers=Reverse[numbers];
|
||||
f[x_]:=Abs[x]^0.5+5 x^3;
|
||||
Do[
|
||||
If[f[i]>overflowVal,
|
||||
Print["f[",i,"]= Overflow"]
|
||||
,
|
||||
Print["f[",i,"]= ",f[i]]
|
||||
]
|
||||
,
|
||||
{i,revNumbers}
|
||||
]
|
||||
]
|
||||
tpk[numbers,400]
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
nums = [];
|
||||
def f(x) x.abs ** 0.5 + 5 * x ** 3 end
|
||||
|
||||
puts "Please enter 11 numbers:"
|
||||
11.times{nums << gets.chomp.to_f}
|
||||
nums = 11.times.map{ gets.to_f }
|
||||
|
||||
nums.reverse.each do |n|
|
||||
res = n.abs ** 0.5 + 5 * n ** 3
|
||||
if res > 400
|
||||
puts "Overflow!"
|
||||
else
|
||||
puts res
|
||||
end
|
||||
nums.reverse_each do |n|
|
||||
print "f(#{n}) = "
|
||||
res = f(n)
|
||||
puts res > 400 ? "Overflow!" : res
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue