program Operaz_matematiche;
uses crt;
var a: array[1..1000]of integer;
b: array[1..1000]of integer;
i,MaxLung,som,n1,k,scelta,base,esp,pot,n,leggi:integer;
mediapon:real;
numeri : array [1..10000] of longint;
Somma,Media,fatt:real;
numero,meta,conta:integer;
procedure home;
begin
repeat
clrscr;
textcolor(7); textbackground(black);
clrscr;
for i:=1 to 80 do write(char(205));
for i:=1 to 24 do
begin
gotoxy(1,i);
write('|');
end;
for i:=1 to 24 do
begin
gotoxy(80,i);
write('|');
end;
for i:=2 to 79 do
begin
gotoxy(i,24);
write(char(205));
end;
for i:=2 to 79 do
begin
gotoxy(i,5);
write(char(205));
end;
for i:=2 to 79 do
begin
gotoxy(i,20);
write(char(205));
end;
gotoxy(34,3); write('TotiPianurese');
gotoxy(31,7); write('1- Media semplice');
gotoxy(31,9); write('2- Media ponderata');
gotoxy(31,11); write('3- Elevamento a potenza');
gotoxy(31,13); write('4- Fattoriale');
gotoxy(31,15); write('5- Divisori di N');
gotoxy(35,22); write('Scelta --> ');read(scelta);
until ((scelta<6)and(scelta>0));
end;
procedure instr;
begin
leggi:=0;
writeln;
writeln;
textcolor(15);
writeln('Inserisci un numero per tornare indietro');
textcolor(3);
write(' Copyright Toty');write(' ',char(169));
writeln;
readln(leggi);
end;
begin
repeat
home;
if scelta=1 then
begin
repeat
clrscr;
k:=7;
textcolor(5);
for i:=1 to 80 do write(char(205));
gotoxy(31,2);
textcolor(lightblue);
writeln('MEDIA SEMPLICE');
textcolor(5);
for i:=1 to 80 do write(char(205));
gotoxy(1,5);
textcolor(yellow);
write('Inserisci il numero degli elementi di cui devi conoscere la media = ');
readln(MaxLung);
until MaxLung>1;
for i := 1 to MaxLung do
begin
textcolor(13);
gotoxy(1,k);
write('Inserisci il ',i,'ø numero = ');
readln (numeri [i]);
Somma := Somma + numeri [i];
k:=k+1;
end;
Media := Somma/MaxLung;
k:=k+1;
gotoxy(1,k);
textcolor(lightgreen);
write('La media Š ',Media :2:2);
instr;
end;
if scelta=2 then
begin
repeat
textbackground(7);
clrscr;
n1:=0;
som:=0;
textcolor(5);
for i:=1 to 80 do write(char(205));
gotoxy(33,2);
textcolor(11);
writeln('MEDIA PONDERATA');
textcolor(5);
for i:=1 to 80 do write(char(205));
writeln;
textcolor(yellow);
write('Da quanti numeri Š composta la lista di cui devi conoscere la media = ');
readln(MaxLung);
until MaxLung>1;
k:=6;
for i:=1 to MaxLung do
begin
textcolor(black);
gotoxy(1,k);
write('Inserisci il ',i,'ø numero = ');read(a[i]);
k:=k+1;
textcolor(lightblue);
gotoxy(1,k);
write('Quante volte troviamo il ',i,'ø numero = '); read(b[i]);
k:=k+1;
som:=som+a[i]*b[i];
n1:=n1+b[i];
end;
mediapon:=som/n1;
writeln;
k:=k+2;
gotoxy(1,k);
textcolor(lightred);
writeln('La media ponderata Š ',mediapon:0:2);
instr;
end;
if scelta=3 then
begin
pot:=1;
clrscr;
textcolor(lightred);
for i:=1 to 80 do write(char(205));
gotoxy(28,2);
textcolor(11);
writeln('ELEVAMENTO A POTENZA');
textcolor(lightred);
for i:=1 to 80 do write(char(205));
textcolor(15);
gotoxy(1,5); write('Inserisci il numero BASE = ');
readln(base);
gotoxy(1,8); write('Inserisci l''esponente = ');
readln(esp);
for i:=1 to esp do
pot:=pot*base;
textcolor(9);
gotoxy(1,11); write('ELEVAMENTO = ',pot);
instr;
end;
if scelta=4 then
begin
clrscr;
textcolor(2);
for i:=1 to 80 do write(char(205));
gotoxy(35,2);
textcolor(4);
writeln('FATTORIALE');
textcolor(2);
for i:=1 to 80 do write(char(205));
textcolor(11);
fatt:=1;
gotoxy(1,5);
repeat write('Inserisci il numero da fattorializzare = ');
readln(n);
if n=0 then
writeln('Il fattoriale di 0 Š ',fatt:0:2);
until n>0;
for i:=2 to n do
begin
fatt:=fatt*i;
end;
writeln;
textcolor(lightgreen);
writeln('Il fattoriale di ',n,' Š : ', fatt:0:2);
instr;
end;
if scelta=5 then
begin
repeat
clrscr;
conta:=0;
textcolor(11);
for i:=1 to 80 do write(char(205));
gotoxy(33,2);
textcolor(lightblue);
writeln('DIVISORI DI N');
textcolor(11);
for i:=1 to 80 do write(char(205));
gotoxy(1,5);
textcolor(15);
write('Digita un numero diverso da 1 per conoscerne i divisori = ');
readln(numero);
until numero>1;
meta:=numero div 2;
for i:=1 to numero do
begin
if (numero mod i)=0 then
conta:=conta+1;
end;
if conta=2 then
begin
writeln;
textcolor(13);
writeln('Il numero non ha divisori (oltre 1 e se stesso)');
instr;
end
else
begin
for i:=2 to meta do
begin
if (numero mod i)=0 then
begin
textcolor(13);
writeln(i,' Š un divisore');
end;
end;
instr;
end;
end;
until leggi<0;
readln();
readln();
end.