Java Printing, Schemes and Mind Maps of Printing

rec1 dproc n T integer if n = 1 then printf %d , n ; else printf %d , n ; rec1 nK1 ; printf %d , n ; end if; end proc; rec1 := proc n::integer.

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 02/28/2023

arij
arij šŸ‡ŗšŸ‡ø

4.8

(8)

230 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
O O
O O
(4)(4)
O O
O O
(3)(3)
O O
O O
(5)(5)
O O
O O
O O
O O
O O
(6)(6)
O O
O O
(1)(1)
(2)(2)
O O
O O
O O
#============================================
# Mar 21. Examples of recursive and iterative programs
#============================================
# number of digits in an integer (recursive)
recnumdig dproc nTposint
if n ! 10 then return 1;
else return 1 C recnumdig trunc n
10 ;
end if;
end proc;
recnumdig := proc n::posint
if n!10 then return 1else return 1Crecnumdig trunc 1 / 10 * nend if
end proc
recnumdig 10000 ; 5
#=========================================
# printing a (palindromic sequence
#=========================================
rec1 dproc nTinteger
if n= 1 then printf " %d ", n;
else printf " %d ", n;
rec1 n K1 ;
printf " %d ", n;
end if;
end proc;
rec1 := proc n::integer
if n=1 then printf " %d ", nelse printf " %d ", n;rec1 n K 1 ; printf " %d ", n
end if
end proc
rec1 10 ;
10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10
#=============recursive max ==========================
mymax da,b/piecewise aOb , a, a %b, b ;
mymax := a,b/piecewise b !a,a,a%b,b
Ld1, 34, 45, 12, 34, 6, 234, 6, 78, 234, 2 ;
L:= 1, 34, 45, 12, 34, 6, 234, 6, 78, 234, 2
recmax dproc kTinteger #return the max of L[1..k]
if k=1 then return L1;
else return mymax L k ,recmax kK1 ;
end if;
end proc;
recmax := proc k::integer
pf3

Partial preview of the text

Download Java Printing and more Schemes and Mind Maps Printing in PDF only on Docsity!

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

Mar 21. Examples of recursive and iterative programs

#============================================

number of digits in an integer (recursive)

recnumdig d proc n T posint if n! 10 then return 1; else return 1 C recnumdig trunc n 10

end if ; end proc ; recnumdig := proc n::posint if n! 10 then return 1 else return 1 Crecnumdig trunc 1 / 10 * n end if

end proc

recnumdig 10000 ; 5 #=========================================

printing a (palindromic sequence

#=========================================

rec1 d proc n T integer if n = 1 then printf " %d ", n ; else printf " %d ", n ; rec1 n K1 ; printf " %d ", n ; end if ; end proc ; rec1 := proc n::integer if n = 1 then printf " %d ", n else printf " %d ", n ; rec1 n K 1 ; printf " %d ", n end if end proc

rec1 10 ; 10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10

#=============recursive max ==========================

mymax d a, b /piecewise a O b , a, a % b, b ; mymax := a, b /piecewise b! a, a, a % b, b L d 1, 34, 45, 12, 34, 6, 234, 6, 78, 234, 2 ; L := 1, 34, 45, 12, 34, 6, 234, 6, 78, 234, 2 recmax d proc k T integer #return the max of L[1..k] if k = 1 then return L 1 ; else return mymax L k , recmax k K 1 ; end if ; end proc ; recmax := proc k::integer

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

OO

if k = 1 then return L 1 else return mymax L k , recmax k K 1 end if

end proc

recmax nops L ; 234

#========sqrt(1 C sqrt(1 C .... sqrt(1 Cx)....))====================

rec2 d proc x T numeric, n T posint if n = 1 then return x; else return sqrt 1 Cevalf rec2 x, n K 1 ; end if ; end proc ; rec2 := proc x::numeric, n::posint if n = 1 then return x else return sqrt 1 Cevalf rec2 x, n K 1 end if

end proc

rec2 3, 4 ;

L d seq rec2 3, i , i = 1 ..30 ; L := 3, 2.000000000, 1.732050808, 1.652891650, 1.628769981, 1.621348199, 1.619057812, 1.618350337, 1.618131743, 1.618064196, 1.618043323, 1.618036873, 1.618034880, 1.618034264, 1.618034074, 1.618034015, 1.618033997, 1.618033991, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.618033989, 1.

#================some symbolic math=============

what is f(f(....f(x)...)) when f(x) = (1-x)K^1?

recfunc d proc n T posint if n = 1 then return^1 1 Kx

else return simplify 1 1 Krecfunc n K 1

end if ; end proc ; recfunc := proc n::posint if n = 1 then return 1 / 1 K x else return simplify 1 / 1 K recfunc n K 1 end if

end proc

recfunc 10 ;

K 1

K 1 Cx L d seq recfunc i , i = 1 ..10 ; L := 1 1 Kx

, K^1 Cx x

, x, K 1 K 1 Cx

, K^1 Cx x

, x, K 1 K 1 Cx

, K^1 Cx x

, x, K 1 K 1 Cx