Documente Academic
Documente Profesional
Documente Cultură
citit de la tastatură : f x
0, dacax 0
Program P1;
uses crt; x=5
var x,f:real; functia este: 2.00
begin
clrscr; x=-3
write('x='); functia este: 9.00
readln(x);
if x<=0 then
f:=sqr(x)
else
f:=0;
writeln('functia este:',f:5:2);
readln;
end.
Program P2;
var x,y,f:integer; x=1
begin y=1
write('x='); functia este:0
readln(x);
write('y='); x=3
readln(y); y=9
if x=y then functia este:1
f:=0
else x=6
if x<y then y=-2
f:=1 functia este:2
else
f:=2;
writeln('functia este:',f);
readln;
end.
x=1
y=1
functia este:0
3 x 2 12, x 10
x2 4
4. De calculat valoarea funcţiei: y
x 1
,10 x 12
ln x 11 7 x
2
, x 12
Program P4;
uses crt;
var x,y:real;
begin x=7
clrscr; functia este:135.00
write('x=');
readln(x); x=11
if x<10 then functia este:12.50
y:=3*sqr(x)-12;
if (x>=10)and(x<12) then
y:=(sqr(x)+4)/(x-1); x=12
if x>=12 then functia este:-1008.00
y:=ln(x-11)-7*sqr(x);
writeln('functia este:',y:5:2);
readln;
end.
citit de la tastatură: f
0,0
x
x
3, x
3
3
x=4
functia este: 1.00
x=-1
functia este:-1.00
x=1
4 x x3 , x 4
100
6. Să se calculeze valoarea funcţiei: y
x
1, 4, 4 x 10
x 2 10 x 2 , x 10
Program P6;
uses crt; x=4
var x,y:real; functia este:64.00
begin
clrscr; x=5
write('x='); functia este:21.40
readln(x);
if x<=4 then
y:=sqrt(4-x)+x*x*x; x=11
if (x>4)and(x<=10) then functia este:233.00
y:=100/x+1.4;
if x>10 then
y:=sqr(x)+10*x+2;
writeln('functia este:',y:5:2);
readln;
end.
Program p9;
uses crt;
var a,b:integer;
begin
clrscr;
write('a='); a=9
readln(a); b=-3
write('b='); -3 9
readln(b);
if(a>b)then
writeln(b,' ',a)
else
writeln(a,' ',b);
readln;
end.
10. Se consideră trei numere întregi. Să se ridice la pătrat numerele pozitive, celelalte
rămânând neschimbate.
program p10;
uses crt;
var a,b,c:integer;
begin
clrscr;
write('Introduce-ti trei numere:');
readln(a,b,c);
if (a>0)and(b>0)and(c>0) then
writeln(sqr(a),' ',sqr(b),' ',sqr(c));
if (a>0)and(b>0)and(c<0) then
writeln(sqr(a),' ',sqr(b),' ',c);
if (a>0)and(b<0)and(c>0) then Introduce-ti trei numere:-5
writeln(sqr(a),' ',b,' ',sqr(c)); -9
if (a>0)and(b<0)and(c>0) then 6
writeln(sqr(a),' ',b,' ',sqr(c)); -5 -9 36
if (a<0)and(b<0)and(c<0) then
writeln(a,' ',b,' ',c);
if (a<0)and(b<0)and(c>0) then
writeln(a,' ',b,' ',sqr(c));
if (a<0)and(b>0)and(c>0) then
writeln(a,' ',sqr(b),' ',sqr(c));
if (a<0)and(b>0)and(c<0) then
writeln(a,' ',sqr(b),' ',c);
readln;
end.
11. Se consideră numerele reale x,y şi z. Să se calculeze: max x y z, xyz .
program p11;
uses crt;
var x,y,z,s,p:real;
begin
clrscr;
write('x='); x=8
readln(x); y=1
write('y='); z=1
readln(y); max(x+y+z, xyz)=10.00
write('z='); numerele sunt egale!
readln(z);
s:=x+y+z; x=2
p:=x*y*z; y=3.5
if (s>p) then z=4
writeln ('max(x+y+z, xyz)=',s:5:2); max(x+y+z, xyz)=28.00
if (s<p) then
writeln('max(x+y+z, xyz)=',p:5:2)
else
writeln('numerele sunt egale!');
readln;
end.
12. Se consideră numerele reale x,y şi z. Să se calculeze: min x 2 y 2 , y 2 z 2 .
program p12;
uses crt;
var x,y,z,s1,s2:real;
begin
clrscr;
write('Introduce-ti trei numere:');
readln(x,y,z); x=-6
s1:=sqr(x)+sqr(y); y=5
s2:=sqr(y)+sqr(z); z=4
if (s1<s2) then min(xx+yy, yy+zz)=41.00
writeln ('min(xx+yy, yy+zz)=',s1:5:2);
if (s1>s2) then
writeln('min(xx+yy, yy+zz)=',s2:5:2);
readln;
end.
13. Se dau două numere naturale a şi b. Să se scrie un program care va verifica dacă
numărul a este divizor comun al lui b.
program p13;
uses crt;
var a,b:integer;
begin
clrscr; a=6
write('a='); b=12
readln(a); a este divizorul lui b
write('b=');
readln(b); a=7
if b mod a=0 then b=15
writeln('a este divizorul lui b') a nu este divizorul lui b
else
writeln('a nu este divizorul lui b');
readln;
end.
14. Se consideră trei numere întregi. Să se scrie un program care aranjează aceste numere
în ordine crescătoare.
program p14; if (b>a)and(b>c) then
uses crt; o:=b;
var a,b,c,m,n,o:integer; if (c>a)and(c>b) then
begin o:=c;
clrscr; writeln(m,' ',n,' ',o);
write('a='); readln;
readln(a); end.
write('b=');
readln(b);
write('c=');
readln(c);
if (a<b)and(a<c) then
m:=a;
if (b<a)and(b<c) then
m:=b;
if (c<a)and(c<b) then a=5
m:=c; b=8
if ((a>b)and(a<c))or((a<b)and(a>c)) then c=1
n:=a; 158
if ((b<a)and(b>c))or((b>a)and(b<c)) then
n:=b;
if ((c<a)and(c>b))or((c>a)and(c<b)) then
n:=c;
if (a>b)and(a>c) then
o:=a;
15. Să se scrie un program care citeşte de la tastatură două numere întregi a şi b. Dacă
primul este mai mic decât al doilea atunci să se afişeze cifra 1, dacă sunt egale cifra 2,
iar dacă al doilea este mai mare ca primul, atunci să se afişeze cifra 10.
program p15;
uses crt;
var a,b:integer;
begin a=5
clrscr; b=8
write('a='); 1
readln(a);
write('b='); a=5
readln(b); b=2
if a<b then 10
writeln('1');
if a=b then a=3
writeln('2'); b=3
if a>b then 2
writeln('10');
readln;
end.
16. Se introduce o cifră de la tastatură. Să se scrie un program care va determina dacă cifra
este pară sau impară.
program p16;
uses crt;
var a:integer;
begin
clrscr; a=8
write('a='); cifra para
readln(a);
if a mod 2=0 then a=9
writeln('cifra para') cifra impara
else
writeln('cifra impara');
readln;
end.
a) 10+6*2/2;
b) (10+6*2)/2;
c) 3-8+21 div 3;
d) (10+6)*2/2;
e) 10+6*(2/2);
f) (2+3) mod 7 – 2.
a) 6*2/2+10;
b) (6*2+10)/2;
c) 21 div 3 +3-8;
d) (10+6)*2/2;
e) (2/2)*6+10;
f) (2+3) mod 7 – 2.
a) 961,0310 2
b) 51410 16
a) 0,03 * 2 = 0,06
961,0310 111000001, 0000011110 1011100001 012 0,06 * 2 = 0,12
0,12 * 2 = 0,24
961 = 2 * 480 + 1 0,24 * 2 = 0,48
480 = 2 * 240 + 0 0,48 * 2 = 0,96
240 = 2 * 120 + 0 0,96 * 2 = 1,92
120 = 2 * 60 + 0 0,92 * 2 = 1,84
60 = 2 * 30 + 0 0,84 * 2 = 1,68
30 = 2 * 15 + 0 0,68 * 2 = 1,36
15 = 2 * 7 + 1 0,36 * 2 = 0,72
7=2* 3+1 0,72 * 2 = 1,44
3=2* 1+1 0,44 * 2 = 0,88
0,88 * 2 = 1,76
0,76 * 2 = 1,52
96110 111000001 2 0,52 * 2 = 1,04
0,04 * 2 = 0,08
0,0310 0,00000111 101011100001012 0,08 * 2 = 0,16
0,16 * 2 = 0,32
0,32 * 2 = 0,64
0,64 * 2 = 1,28
0,28 * 2 = 0,56
0,56 * 2 = 1,12
0,12 * 2 = 0,24
b) 51410 0216
514 = 16 * 32 + 2
32 = 16 * 2 + 0
if a = 1 then case a of
begin 1 : begin
a:=10; a:=10;
writeln(a); writeln(a);
end; end;
if a = 2 then 2 : writeln(‘eronat’);
writeln(‘eronat’); 3 : writeln(‘tot’);
if a = 3 then
writeln(‘tot’);
22. În secvenţele de mai jos schimbaţi instrucţiunea case prin instrucţiunea if:
a) p:=false; (A)
b) i:=3.375; (F)
c) b:=’ha’; (A)
d) x+3:=y; (A)
e) j:=round(x/2); (F)
f) a:=’+’; (A)
g) x:=i+j mod 7; (A)
h) q:=odd(j+i div 5); (A)
i) y:=275; (A)