Pascal

Materie:Appunti
Categoria:Ricerche

Voto:

2 (2)
Download:102
Data:18.05.2000
Numero di pagine:1
Formato di file:.doc (Microsoft Word)
Download   Anteprima
pascal_1.zip (Dimensione: 5.79 Kb)
trucheck.it_pascal.doc     30 Kb
readme.txt     59 Bytes


Testo

Questi sono 2 problemi standard in linguaggio di programmazione pascal(per seconda superiore)

CALCOLARE LA POTENZA ESP-ESIMA(SIA CON INDICE POSITIVO CHE NEGATIVO) DI UN NUMERO QUALUNQUE N.
Program potenza;
uses crt;
var n, pot: real; esp, i : integer;
Begin
clrscr;
writeln('Fare la potenza di un qualunque numero n ');
write('Inserire n : ');
readln(n);
write('Inserire esponente : ');
readln(esp);
if n = 0 then if esp = 0 then writeln(' Indeterminato ')
else writeln('Risulta 0')
else if esp = 0 then witeln('Risulta 1')
else Begin
pot : = 1;
for i : = 1 to abs(esp) do
pot : = pot*n;
if esp < 0 then pot : = 1/pot;
writeln('Il risultato è ',pot:10:3)
end;
repeat until keypressed;
end.

CALCOLARE TUTTI IPOSSIBILI DIVISORI DI UN NUMERO
Program:divisori;
uses crt;
var n, a:integer; c: real;
Begin
clrscr;
writeln('Inserire un numero n e calcolare tutti i divisori');
write('Inserire n : ');
readdln(n);
if n = 0 then writeln('Zero fratto qualsiasi numero dà 0')
else Begin
a : = n ;
Repeat c : = n/a;
if frac(c) = 0 then writeln(c:6:2);
a : = a - 1;
until a < = 1;
end;
repeat until keypressed;
end.

Esempio