0% found this document useful (0 votes)
18 views6 pages

Algoritmi Fundamentali 2

This document provides pseudocode for fundamental algorithms: 1. Interswapping values of two variables without using a temporary variable. 2. Reading and reversing the digits of a natural number. 3. Adding two natural numbers by successively adding their digits. 4. Finding all distinct factors of a natural number in increasing order.

Uploaded by

Alexandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Algoritmi Fundamentali 2

This document provides pseudocode for fundamental algorithms: 1. Interswapping values of two variables without using a temporary variable. 2. Reading and reversing the digits of a natural number. 3. Adding two natural numbers by successively adding their digits. 4. Finding all distinct factors of a natural number in increasing order.

Uploaded by

Alexandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

FUNDAMENTAL

Ali
ALGORITMi FUNDAMENTAL -

PSEUAOCOD/ LMBAJ C++

Interschimbaner valowts
due variatio valatal
1 .
a
anx &N auxiliar
a = b a < a+ b
b =
aux b < a -
b
a < a -

b
2 .
Greberance cifrelo mi numer natural i
citeste i

at'timp ** expecta
In
deterrhin ultima
cifra
↳getreate softe
-

m
(n/10]
= Il elimin ultima sifte
Aps .
1 : Sate
famefe un numat in eifrete in ordin
inverta (oglicdilul -
-- -

citeste
No
o to executa numeral actfel farmot
I
-t
ga
timp
Es
are
cifrel ordine
lote
in
age
M L
inversa ummoralia -

die ot
Apt2 fa meElaemet Mefree please
:

Sass
als si
in nor
citists W

750
· xoveFormer
zu Latelin
in

its
e

mate
Hix
- - -

ot
dain 2 % b= e all
Is
n = (w/10]
.
3 Cmmde ti Cmmme a done mymere naturale nemule a sib
Brin sideri sucessive
I
3 .
1 .

Algorit must hi Eid 3h.

citete
E
a ,
b citerte ab
E ax b cat timp a + b executa
pcat

It
executi b to
timp dai b

Sm
a>
rt a Yo otunci a=a -
b
E altfel b= b -
a

de E a
emmdes- a
emmme -> f/emmele
4 .

Divigoin uni memor natural i


in adine cresiatoare
Afrarca tuturor diviforitos
li

n
4 1 .
.

cilerte w
S
d= n/2 executa
pentere i
-

scie
,

daio -/ d
·

Fi "unei scrie d

in

(in
4 2 . .

Algorith ecient -
care
generati divifii -
pereci priml-ultival
:

penultimat Samd)
,
aldrilea-
citeste y

timbay

d = 1 i , executa
E
2++
peute

I
-

for (d 1 ; d*d< wid++)


,

daii
nid=otunci
=

if (id 0)

I
d
serie / =
=

dd (n/d] = ↳ cont dan ;


dai dE dd dd n/d ;
Is
=

schiedd if d! dd)
ohnei
'coutcdda-
=

5 Primalitates uni memor natural n


I y
Fundie returneopiis1 docon-prin
.

e++ cove
einn
altfel
ok=1 : // mesupun pric
is n eith out prim(intn)
↳ if (n=1) Relzu
-

if(n 1) dxd OK 0; <


=
o
;
; d
+
for (d 2:
=
=
n +

for (intd =
2; d+ d< =

n; d +

+)
if (nyd 00K 0 ; =
= =

if Injd==o return o
;
if (0K==1) cout"s prim"; Return 1
;
the cout" nee prim"; y
Vitirea
reputati Is Melucarea for citire
pe motura and
↳ .
a n unmere
.

6 1 Cincw ↳2 . Citive din firer Nis ,


anoaste
S
.

for Li=lil<=n ; it+ numoral de numere


. .

while (fin x)
↳enehereafter
y
1 Melecreati pex
donis
63
prelcrance a humere citite consecutiv
.
.

fixxx ; e
y
white
in

n prelecresti pe
x si y
X
y,
=

y
trei
64 . .

pslucrome a memere citite consecutiv


fix x< y;
while (fix z)
a prelecrepi ps x ,
y s z

x
y;
=

y =
z;
y
I .

Descomponenes in factor primi a veni unwar natural w

is ++
citeste
d=
S
w
Optimizover algritmu
2 ein wi
! =/executa d
cat
timpk n 2

I
=
-

= 0
while [dxdc =

n)
cat nyd executa 4k
timPk +
0 0
;

Trai kotunei
=

while/nyd
=

= = 0)

(1-edick
n =
[/d]

Io serisd k , if ;
d= dH yd + +

if I n ! =1) coutn'-' 1;

①I
Refultateimportede ...
k

① .
Anmiral divigoite linette s, nd=(k +1)(k2+1)
, ....

(kx+1)
↳ 2
.

. AuxildeWewe time up H de in
x-e) Here ene

83 Numoral perschlor (a b) >


(2b +) (2bat1)
,

(akx+1)
. .

A3
a ban
surpisttes to
urp
=

en ,
. . . .

emmme(a(b) =
u

8 4 .
.
Same
W
dirgontor his $ 4 .

So- dete that · ....


↑ pa exce
% Conversion unmenelle notamale dis bes

Bage
.
to
bei

als 1D
Exn 29 puter

·
=

I -

b = 2 a

the
1
m

*
14 0 10 01
3
W

· I le
7 1

i
d

*
1000
ene 3 1
X /
0
10 on

·
I
=

*
10000

entert
-
w
,
b gata
I

X E O

Icat
Himp wo executi

Frie
.

RE %ob
R*
x
P
=
x +

* 1
p =
p
n = n/b

X
bafei
-
all
No .
Conversia unserelor naturale din Bagob in Baja 10 (2c = b( =
9)
-puteli
1AC+ 1x *

exentocb/x e
E m= On X
=

12 + 0* C + =
**
en

b 4 D
13(10)
=

2 1 +
0+ +
=

O 2
citests nib

I !) is
I

"
X O
1
p< to executa
cat
timp

Fre
c= m % 14
Xt **
Igata!
X 5
p
b
p px
N in

firul Fibonace (pirusi recnrente)


thi

1 1 2 5 5 I 13 21 34 , 55 29 144 233 377


, , , , , , , , , , / , ,
. . .

terment
11 .
1 .
Generance
plimilos a Fibonacci

citete e
·

Datin =
1 otunei Scie 1

altfel scie a, d


.

I
executi
penbu it 3 i
,

In
c = n +
b
scrie C

ac b
btC
M 2
. .
Sa se
verifice daio un numer xete termen Fibonacci
Ex=S :
se va afiraL
DA
x = 7 :

Se va
afisa Nr

citerte X
I
a51

b51
b<x executa
cat
timp
Is
25 a+ b
a b =

b 5 C

Daco x = b otunci scie"DA"


Li .
afffel scie "I"

12 .

Exponentielea rapida (sidicaves le


putore in
Fimp logariti)
O Y n 25
ni in

aa /Saw
al= =
n. = n .
=
.

O
0 M

1024 1= 1024
.
.

citeste a ,
w

p1
executa
cat-timp to

I
daso n % 2 =
0 otunei as axa

n
= n/2

altfel p =p *a

n = n -
1

You might also like