Concetti Chiave
- Il programma permette di inserire una serie di 5 numeri interi tramite la procedura INPUT.
- Utilizza l'ordinamento a bolle per sistemare i numeri in ordine crescente nella procedura SISTEMA_NUMERI.
- La procedura MAGGIORE_E_MINORE calcola e visualizza il numero maggiore e il numero minore dell'array.
- La procedura OUTPUT stampa i numeri ordinati in ordine crescente.
- Il programma richiede l'interazione dell'utente per continuare tra le varie fasi tramite la procedura PROSEGUIRE.
program procedura;
uses crt;
(*Data una serie di 5 numeri, trovare il maggiore, il minore e sistemarli in ordine crescente*)
var A: array [1..5] of integer;
I,J,X: integer;
tasto:char;
procedure INPUT;
begin
clrscr;
writeln (' ');
for I:=1 to 5 do
begin
write ('Introdurre il numero intero n',I,'=');
readln (A);
end;
end;
Ordinamento dei numeri
procedure SISTEMA_NUMERI;
begin
for I:=1 to 4 do
for J:=I+1 to 5 do
if A>A[J] then
begin
X:=A[J];
A[J]:=A;
A:=X;
writeln (' ');
end;
end;
procedure MAGGIORE_E_MINORE;
begin
writeln (' ');
writeln ('Il numero minore Š ', A[1]);
writeln ('Il numero maggiore Š ', A[5]);
end;
procedure OUTPUT;
begin
writeln (' ');
writeln ('Elenco dei 5 numeri in ordine crescente: ');
writeln (' ');
for I:=1 to 5 do
writeln (A, ' ');
end;
procedure PROSEGUIRE;
begin
writeln ('Digitare un tasto per continuare');
repeat
tasto:=readkey;
until tasto chr(32);
end;
begin
INPUT;
writeln (' ');
PROSEGUIRE;
SISTEMA_NUMERI;
writeln (' ');
PROSEGUIRE;
OUTPUT;
writeln (' ');
PROSEGUIRE;
MAGGIORE_E_MINORE;
PROSEGUIRE;
write (' ');
writeln (' --TERMINE PROGRAMMA-- ');
readln
end.
Domande da interrogazione
- Come si inseriscono i numeri nel programma?
- Qual è la logica utilizzata per ordinare i numeri?
- Come vengono visualizzati il numero maggiore e il numero minore?
I numeri vengono inseriti tramite la procedura INPUT, che richiede all'utente di introdurre 5 numeri interi uno alla volta.
I numeri vengono ordinati in modo crescente attraverso la procedura SISTEMA_NUMERI, che utilizza un doppio ciclo per confrontare e scambiare i valori nell'array A.
La procedura MAGGIORE_E_MINORE stampa il numero minore (il primo elemento dell'array) e il numero maggiore (l'ultimo elemento dell'array) dopo che i numeri sono stati ordinati.