203.2006
TRANSCRIPT
![Page 1: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/1.jpg)
ISTRUCTIUNEA IF
PROBLEMA 1.1.1Se considera trei numere intregi.Sa se scrie un program care determina numarul mai mare.
Program P1_1; Uses crt; Var a,b,c,d,f:integer; Begin clrscr; Writeln('introdu numerele a,b,c:'); Readln(a,b,c); If a>b Then d:=a Else d:=b; If c>d Then f:=c Else f:=d; Writeln('f=', f); Readkey; End.
1
![Page 2: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/2.jpg)
PROBLEMA 2.1.2Se considera patru numere intregi.Sa se scrie un program care determina numarul mai mic. Program P1_2; Uses crt; Var a,b,c,d,f,e,g:integer; Begin clrscr; Writeln('introdu numerele a,b,c,d:'); Readln(a,b,c,d); If a<b Then f:=a Else f:=b; If c<d Then e:=c Else e:=d; If f<e Then g:=f Else g:=e; Writeln('g=', g); Readkey; End.
2
![Page 3: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/3.jpg)
PROBLEMA 3.1.3Se considera doua numere intregi.Daca primul numar este negativ , atunci suma lor se micsoreaza de 5 ori,in caz contrar-se mareste de 5 ori. Program P1_3; Uses crt; Var a,b:integer; x:real; Begin clrscr; Writeln('introdu numerele a,b:'); Readln(a,b); If a<0 Then x:=(a+b)/5 Else x:=5*(a+b); Writeln(x:5:4); Readkey; End.
3
![Page 4: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/4.jpg)
PROBLEMA 4.1.4Se considera doua numere intregi.Daca primul numar este mai mare decit modulul celui de-al doi lea numar,atunci primul numar se micsoreaza de trei ori,in caz contrar nu-merele ramin neschimbate.
Program P1_4; Uses crt; Var a,b:integer; x:real; Begin clrscr; Writeln('introdu numerele a,b:'); Readln(a,b); If a>abs(b) Then x:=a/3 Else Begin a:=a; b:=b; End; Writeln(x:5,a:5,b:5); Readkey; End.
4
![Page 5: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/5.jpg)
PROBLEMA 5.1.5Se considera doua numere intregi.Daca primulnumar este mai mare decit modulul celui de-al doilea numar,atunci primul numar se mic-soreaza de trei ori,in caz contrar numerele ramin neschimbate.
Program P1_5; Uses crt; Var a,b:integer; x:real; Begin clrscr; Writeln('Introdu numerele a, b:'); Readln(a,b); If a>abs(b) Then x:=a/3 Else Writeln(a:5,b:5); Writeln(x:5); Readln; Readkey; End.
5
![Page 6: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/6.jpg)
PROBLEMA 6.1.6;Se considera doua numere intregi.Daca primul numar este pozitiv, atunci el se mareste cu 100,in caz contrar numerele ramin neschimba-te.
Program P1_6; Uses crt; Var a,b:integer; Begin Clrscr; Writeln('Introdu numarul a='); Readln(a); Writeln('Introdu numarul b='); Readln(b); If a>0 Then Writeln(a+100,' ',b) Else Writeln(a,' ',b); Readln; Readkey; End.
6
![Page 7: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/7.jpg)
PROBLEMA 7.1.7Se considera doua numere intregi diferite.Sase afiseze numerele in urmatoarea ordine:maiintii cel mai mare, apoi cel mai mic.
Program P1_7; Uses crt; Var a,b,aux:integer; Begin clrscr; Writeln('Introdu numerele a, b:'); Readln(a,b); If a>b Then Begin aux:=a; a:=b; b:=aux; End; Writeln(a,' ',b); Readln; Readkey; End.
7
![Page 8: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/8.jpg)
PROBLEMA 8.1.8Se considera doua numere intregi.Sa se afiseprimul numar, daca el este mai mare decit aldoilea,in caz contrar sa se afiseze ambelenumere.
Program P1_8; Uses crt; Var a,b:integer; Begin clrscr; Writeln('Introdu numerele a, b:'); Readln(a,b); If a>b Then Write('a=',a) Else Writeln(a:5,b:5); Readln; Readkey; End.
8
![Page 9: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/9.jpg)
PROBLEMA 9.1.9Se considera trei numere intregi.Sa se ridi-ce la patrat numerele negative,celelalte ra-minind neschimbate.
Program P1_9; Uses crt; Var a,b,c:integer; x,y,z:real; Begin clrscr; Writeln('Introdu numerele a, b,c:'); Readln(a,b,c); If a<0 Then Begin x:=a*a; Writeln(x:5:4); End Else Writeln(a:5);
9
![Page 10: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/10.jpg)
If b<0 Then Begin y:=b*b; Writeln(y:5:4); End Else Writeln(b:5); If c<0 Then Begin z:=c*c; Writeln(z:5:4); End Else Writeln(c:5); Readln; Readkey; End.
PROBLEMA 10.1.10Se considera trei numere intregi.Daca toatesunt pozitive sa se afiseze numarul mai maredintre al doilea si al treilea numar,in cazcontrar sa se calculeze media aritmetica aprimelor doua numere.
Program P1_10; Uses crt; Var a,b,c,k:integer; s:real; Begin clrscr; Writeln('Introdu numerele a, b,c:'); Readln(a,b,c); If (a>0) and (b>0) and (c>0) Then Begin
10
![Page 11: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/11.jpg)
If b>c Then k:=b Else k:=c; Writeln(k:5); End Else s:=a+b; Writeln(s:5:4); Readln; Readkey; End.
PROBLEMA 11.1.11Se considera trei numere intregi.Daca sumaprimelor doua este pozitiva, atunci sa seafiseze numerele in ordine crescatoare,incaz contrar sa se afiseze numarul maxim din-tre ultimele doua numere.
Program P1_11; Uses crt; Var a,b,c,t,k:integer; s:real; Begin clrscr; Writeln('Introdu numerele a, b,c:'); Readln(a,b,c);
11
![Page 12: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/12.jpg)
s:=a+b; If s>0 Then Begin If a>b Then Begin t:=a;a:=b;b:=t;End; If b>c Then Begin t:=b;b:=c;c:=t;End; If a>b Then Begin t:=a;a:=b;b:=t;End; Writeln(a:5,b:5,c:5) End Else Begin If b>c Then k:=b Else k:=c; Writeln(k:5); End; Readln; Readkey; End.
PROBLEMA P12.1.12Se considera trei numere intregi ,doua dintre care sunt egale. Sa se scrie un program care afiseaza numarul diferit de celelalte doua.
Program P1_12; Uses crt; Var a,b,c:integer; Begin Clrscr; Writeln('Intodu numerelea,b,c:'); Readln(a,b,c); If a=b Then Write('Numarul diferit
12
![Page 13: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/13.jpg)
este:',c); If a=c Then Write('Numarul diferit este:'b); If c=b Then Write('Numarul diferit este:'a); Readkey; Readln; End.
PROBLEMA 13.1.13Sa se scrie un program care citeste doua nu-mere intregi x,y si afiseaza 0,daca numerele citite sunt egale,afiseaza 1,daca primul es-te mai mic decit al doilea si afiseaza 2, daca primul numar este mai mare decit al do-ilea.
Program P1_13; Uses crt; Var x,y:integer;
13
![Page 14: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/14.jpg)
Begin clrscr; Writeln('Introdu numerele x, y:'); Readln(x,y); If x=y Then Writeln('0'); If x<y Then Writeln('1'); If x>y Then Writeln('2'); Readln; Readkey; End.
Problema14.1.14De la tastatura se citeste una din urmatoare-le cifre romane:I,V,X,L,C,D,M.Sa se scrie un program care afiseaza numarul zecimal сores-punzator cifrei citite.
Program P13_2; Uses crt; Var i:integer;
14
![Page 15: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/15.jpg)
c:char; Begin Clrscr; i:=0; Writeln('Intodu una din cifrele I,V,X,L,C,D,M:'); Readln(c); If c='I' Then i:=1; If c='V' Then i:=5; If c='X' Then i:=10; If c='L' Then i:=50; If c='C' Then i:=100; If c='D' Then i:=500; If c='M' Then i:=1000; If i=0 Then Writeln(c, '-nu este o cifra romana') Else Writeln(i); Readln; End.
PROBLEMA 15.1.15De la tastatura se introduce o litera din alfabetul latin.Sa se determine daca litera este vocala sau consoana.
Program P1_15; Uses crt;
15
![Page 16: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/16.jpg)
Var c:char; Begin clrscr; Writeln('Introdu caracterul c:'); Readln(c); If(c='B')or(c='C')or(c='D')or(c='E') or(c='F')or(c='G')or(c='H')or(c='J') or(c='K')or(c='L')or(c='M')or(c='N') or(c='P')or(c='Q')or(c='R')or(c='S') or(c='T')or(c='V')or(c='W')or(c='X') or(c='Y')or(c='Z')or(c='b')or(c='c') or(c='d')or(c='f')or(c='g')or(c='h') or(c='j')or(c='k')or(c='l')or(c='m') or(c='n')or(c='p')or(c='q')or(c='r') or(c='s')or(c='t')or(c='v')or(c='w') or(c='x')or(c='y')or(c='z')Then Writeln('Consoana'); If (c='A')or(c='E')or(c='U')or(c='I') or(c='O')or (c='a')or( c='e')or(c='u') or(c='i')or(c='o')Then Writeln('Vocala') ; Readln; Readkey; End.
PROBLEMA 16.1.16De la tastatura se introduce o cifra.Sa se determine daca cifra este para.
Program P1_16;
16
![Page 17: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/17.jpg)
Uses crt; Var n:0..9; Begin clrscr; Writeln('Introdu n:'); Readln(n); If n mod 2=0 Then Writeln('Cifra este para') Else Writeln('Cifra este impara'); Readln; Readkey; End.
PROBLEMA 17.1.17Se considera trei numere reale.Sa se scrie un program care determina daca aceste numere
17
![Page 18: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/18.jpg)
reprezinta lungimile laturilor unui triungi si in caz afirmativ sa se:a)calculeze perimetrul triungiului;b)determine natura triungiului in dependenta de lungimile laturilor.
Program P1_17; Uses crt; Var a,b,c:real; p:real; Begin clrscr; Writeln('Introdu numerele a, b,c:'); Readln(a,b,c); If((a+b)>c) and ((a+c)>b) and (b+c)>a) Then Begin p:=a+b+c; If (a=b) or (b=c) or (a=c) Then Writeln('Isoscel'); If (a=b) and(b=c) and(a=c) Then Writeln('Echilateral'); If (a<>b) and (b<>c) and (a<>c) Then Writeln('Scalen'); Writeln(p:6:4); End; Readln; Readkey; End.
PROBLEMA 18.1.18
18
![Page 19: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/19.jpg)
Se considera trei puncte cu coordonatele date:A(x1,y1),B(x2,y2),C(x3,y3).Sa se determine care din puncte se afla mai aproape de ori-ginea de coordonate.
Program P1_18; Uses crt; Var x1,y1,x2,y2,x3,y3,d1,d2,d3:real; Begin Clrscr; Writeln('Introdu x1,y1,x2,y2,x3,y3:'); Readln(x1,y1,x2,y2,x3,y3); d1:=sqrt(x1*x1+y1*y1); d2:=sqrt(x2*x2+y2*y2); d3:=sqrt(x3*x3+y3*y3); If (d1<d2) and (d1<d3) Then Writeln('A'); If (d2<d1) and (d2<d3) Then Writeln('B'); If (d3<d1) and (d3<d2) Then Writeln('C'); Readln; Readkey; End.
19
![Page 20: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/20.jpg)
PROBLEMA 19.1.19Trei vinzatori x,y,z au vindut portocale.X a vindut 170 kg la pretul de 8.5 lei,y-350 kg cu 8.8 lei,iar z-150 kg cu 9 lei chilogra-mul.Sa se scrie un program care calculeaza pretul mediu de comercializare;cine din vin-zatori a obtinut cea mai mare suma de lacomercializarea portocalelor.
Program P1_19; Uses crt; Var p,p1,p2,p3:real; q,w,e,r,t,y:real; Begin Clrscr; Writeln('Introdu numerele q,w,e,r,t,y:'); Readln(q,w,e,r,t,y); p1:=q*w; p2:=e*r; p3:=t*y; p:=(p1+p2+p3)/3; If (p1>p2) and (p1>p3) Then Writeln('x'); If (p2>p1) and (p2>p3) Then Writeln('y'); If (p3>p1) and (p3>p2) Then Writeln('z'); Writeln(p:5:3); Readln; Readkey; End.
20
![Page 21: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/21.jpg)
PROBLEMA 20.1.20Se considera numerele reale x,y si z.Sa se calculeze:a)max(x+y+z,xyz);b)min(x*x+y*y,y*y+z*z)+4.
Program P1_20; Uses crt; Var x,y,z:real; max,min:real; Begin clrscr; Writeln('Introdu numerele x,y,z:'); Readln(x,y,z); If (x+y+z)>x*y*z Then max:=x+y+z Else max:=x*y*z; If (x*x+y*y)<(y*y+z*z) Then min:=x*x+y*y+4 Else min:=y*y+z*z+4; Writeln(max:6:3); Writeln(min:6:3); Readln; Readkey; End.
21
![Page 22: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/22.jpg)
PROBLEMA 21.1.21Sa se calculeze valoarea functiei f definita pe multimea numerelor reale,pentru un x ci-tit de la tastatura x*x ,daca x<=0, f= 0 ,daca x>0.
Program P1_21; Uses crt; Var x,f:real; Begin clrscr; Writeln('Introdu x:'); Readln(x); If x<=0 Then f:=x*x; If x>0 Then f:=0; Writeln(f:6:4); Readln; Readkey; End.
22
![Page 23: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/23.jpg)
PROBLEMA 22.1.22Sa se calculeze valoarea functiei f definita pe multimea numerelor reale,pentru un x ci-tit de la tastatura x ,daca x<0, f= 0 ,daca 0<=x<=3, x-3 ,daca x>3 .
Program P1_22; Uses crt; Var x,f:real; Begin clrscr; Writeln('Introdu x:'); Readln(x); If x<0 Then f:=x; If x>3 Then f:=x-3; If (x>=0) and (x<=3) Then f:=0; Writeln(f:6:4); Readln; Readkey; End.
23
![Page 24: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/24.jpg)
PROBLEMA 23.1.23Sa se scrie un program pentru rezolvarea ecuatiei liniare de forma: ax+b=0 .
Program P1_23; Uses crt; Var x,a,b:real; Begin clrscr; Writeln('Introdu a,b:'); Readln(a,b); If a=0 Then Writeln('x n-are solutie'); If a<>0 Then x:=-b/a; Writeln(x:6:4); Readln; Readkey; End.
24
![Page 25: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/25.jpg)
PROBLEMA 24.1.24Sa se scrie un program pentru rezolvarea ecuatiei patrate a*x*x+b*x+c=0 cu coficienti reali.
Program P1_24; Uses crt; Var x,a,b,c,d:real; Begin clrscr; Writeln('Introdu a,b,c:'); Readln(a,b,c); d:=b*b-4*a*c; If d<0 Then Writeln('Ecuatia n-are slutie'); If d=0 Then Writeln(-b/(2*a):5:2); If d>0 Then Begin Writeln((-b+sqrt(d)/(2*a)):5:2); Writeln((-b+sqrt(d)/(2*a)):5:2); End; Readln; Readkey; End.
25
![Page 26: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/26.jpg)
PROBLEMA 25.1.25Sa se scrie un program pentru rezolvarea ecuatiei bipatrate a*x*x*x*x+b*x*x+c=0 cu coficienti reali.
Program P1_25; Uses crt; Var a,b,c,d,t,t1,t2:real; Begin clrscr; Writeln('Introdu a,b,c:'); Readln(a,b,c); d:=b*b-4*a*c; If d<0 Then Writeln('Ecuatia n-are solutie'); If d=0 Then t:=(-b/(2*a)); Writeln('t=',t); If d>0 Then Begin t1:=(-b+sqrt(d)/(2*a)); t2:=(-b-sqrt(d)/(2*a)); Writeln('t1= ' , t1 ,' t2= ,t2 ) End;
26
![Page 27: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/27.jpg)
If t>0 Then Begin Writeln(sqrt(t)); Writeln(-sqrt(t)); End; If t1>0 Then Begin Writeln(sqrt(t1)); Writeln(-sqrt(t1)); End; If t2>0 Then Begin Writeln(sqrt(t2)); Writeln(-sqrt(t2)); End; Readln; Readkey; End.
Instructiunea Case
PROBLEMA 26.2.1Se citeste numarul de ordine al lunii.Sa se scrie un program care afiseaza anotimpul co-respunzator lunii.
Program P2_1; Uses crt; Var n:1..12; Begin Clrscr; Writeln('introdu un numar intre 1..12 :'); Readln(n); Writeln('Raspuns'); Case n Of 1,2,12 :Write ('Iarna'); 3,4,5 :Write ('Primavara'); 6,7,8 :Write ('Vara'); 9,10,11:Write ('Toamna');
27
![Page 28: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/28.jpg)
Else Write('Nu exista asa luna '); End; Readkey; Readln; End.
PROBLEMA 27.2.2Se citeste de la tastatura numarul de ordine al zilei saptaminii.Sa se scrie un program care afiseaza numarul de lectii pe care le aveti in aceasta zi.
Program P2_2; Uses crt; Var n:1..5; Begin Clrscr; Writeln('introdu un numar intre 1..5 :'); Readln(n); Writeln('Raspuns'); Case n Of 1 :Write ('Cinci'); 2 :Write ('Sase'); 3 :Write ('Patru');
28
![Page 29: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/29.jpg)
4 :Write ('Sapte'); 5 :Write ('Opt') ; Else Write('Zi de odihna '); End; Readkey; Readln; End.
PROBLEMA 28.2.3Se citeste numarul de ordine al lunii.Sa se scrie un program care afiseaza numarul de zile corespunzator lunii.
Program P2_3; Uses crt; Var n:1..12; Begin Clrscr; Writeln('introdu un numar intre 1..12 :'); Readln(n); Writeln('Raspuns'); Case n Of 1,3,5,7,8,10,12 :Write ('31'); 2 :Write ('28 sau 29');
29
![Page 30: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/30.jpg)
4,6,9,11 :Write ('30'); Else Write('Nu exista asa luna '); End; Readkey; Readln; End.
PROBLEMA 29.2.4De la tastatura se citeste o cifra.Sa se scrie un program care afiseaza denumirea acesteia.
Program P2_4; Uses crt; Var n:0..9; Begin Clrscr; Writeln('introdu un numar intre 0..9 :'); Readln(n); Writeln('Raspuns'); Case n Of
30
![Page 31: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/31.jpg)
0 :Write ('Zero'); 1 :Write ('Unu'); 2 :Write ('Doi'); 3 :Write ('Trei'); 4 :Write ('Patru'); 5 :Write ('Cinci'); 6 :Write ('Sase'); 7 :Write ('Sapte'); 8 :Write ('Opt'); 9 :Write ('Noua'); Else Write('Nu exista cifra '); End; Readkey; Readln; End.
PROBLEMA 30.2.5De la tastatura se citeste o litera din al-fabetul latin.Sa se scrie un program care determina daca litera introdusa reprezinta o vocala sau o consoana.
Program P2_5; Uses crt; Var n:char; Begin Clrscr; Writeln('introdu o litera :'); readln(n);
31
![Page 32: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/32.jpg)
Writeln('Raspuns:'); Case n Of 'A','a','E','e','U','u','I','i','O','o' :Write ('Vocala'); 'q','Q','w','W','R','r','T','t', 'P','p','S','d','D','f', 'F','g','G','h','H','j','J','k','K', 'l','Z','z','X','x', 'C','c','V','v','B','b','N', 'n','M','m' :Write ('Consoana'); Else Write('Nu exista asa litera '); End; Readkey; Readln; End.
PROBLEMA 31.2.6De la tastatura se citasc doua numere in-tregi diferite de zero si una din operatiile aritmetice +,-,*,/.Daca a fost introdus sem-nul '+',sa se calculaze suma numerelor,daca a fost introdus semnul '-',sa se calculeze diferenta numerelor,daca a fost introdus semnul '*',sa se calculeze produsul lor,daca a fost introdus semnul '/',sa se calculeze citul lor.
32
![Page 33: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/33.jpg)
Program P2_6; Uses crt; Var n:char; a,b:integer; Begin Clrscr; Writeln('introdu operatia :'); Readln(n); Writeln('Introdu numerele a,b:'); Readln(a,b); Writeln('Raspuns'); Case n Of '+' :Write (a+b:5); '-' :Write (a-b:5); '*' :Write (a*b:5); '/' :Write (a/b:5:3); Else Write('Nu exista operatie'); End; Readkey; Readln; End.
PROBLEMA 32.2.7De la tastatura se citeste urmatoarele cifre romane:I,V,X,L,C,D sau M.Sa se scrie un pro-gram care afiseaza numarul zecimal corespun-zator cifrei citite.
Program P2_7; Uses crt; Var n:char;
33
![Page 34: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/34.jpg)
a,b:integer; Begin Clrscr; Writeln('Introdu cifra:'); Readln(n); Writeln('Raspuns'); Case n Of 'I' :Write ('1'); 'V' :Write ('5'); 'X' :Write ('10'); 'L' :Write ('50'); 'C' :Write ('100'); 'D' :Write ('500'); 'M' :Write ('1000'); Else Write('Nu exista asa cifra'); End; Readkey; Readln; End.
PROBLEMA 33.2.8De la tastatuta se introduce o data din luna aprilie (anul 2002). Sa se determine ce zi a fost la aceasta data(denumirea zilei),daca se stie ca 1 aprilie a fost simbata.
Program P2_8;
34
![Page 35: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/35.jpg)
Uses crt; Var data:1..30; Begin Clrscr; Write('Itrodu un numar intre 1..30:'); Readln(data); Write('Raspuns: '); Case data Of 1,8,15,22,29:Writeln('Simbata'); 2,9,16,23,30:Writeln('Duminica'); 3,10,17,24 :Writeln('Luni'); 4,11,18,25 :Writeln('Marti'); 5,12,19,26 :Writeln('Miercuri'); 6,13,20,27 :Writeln('Joi'); 7,14,21,28 :Writeln('vineri') Else Writeln('N-ati introdus corect data'); End; Readln; Readkey;End.
PROBLEMA 34.2.9De la tastatuta se citeste unul dintre urma-toarele numere:1,5,10,50,100,500 sau 1000.Sa se scrie un program care afiseaza cifra ro-mana corespunzatoare numarului citit.
35
![Page 36: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/36.jpg)
Program P2_9; Uses crt; Var x:1..1000; Begin Clrscr; Write('Itrodu 1,5,10,50,100,500 sau 1000:'); Readln(x); Write('Raspuns: '); Case x Of 1 :Writeln('I'); 5 :Writeln('V'); 10 :Writeln('X'); 50 :Writeln('L'); 100 :Writeln('C'); 500 :Writeln('D'); 1000:Writeln('M') End; Readln; Readkey; End.
Instructiunile For,Repeat,While
PROBLEMA 35.3.1
36
![Page 37: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/37.jpg)
Sa se scrie un program care afiseaza pe ecran numerele naturale mai mici sau egale cu n.
Program P3_1; Uses crt; Var i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do Writeln(i); Readkey; Readln; End.
37
![Page 38: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/38.jpg)
PROBLEMA 36.3.2Sa se scrie un program care afiseaza pe ecran numerele naturale impare mai mici sau egale cu n.
Program P3_2; Uses crt; Var i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do If i mod 2<>0 Then Writeln(i); Readkey; Readln; End.
38
![Page 39: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/39.jpg)
PROBLEMA 37.3.3Sa se scrie un program care afiseaza pe ecran numerele naturale mai mici sau egale cu n,care-s divizibile cu 5.
Program P3_3; Uses crt; Var i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do If i mod 5=0 Then Writeln(i); Readkey; Readln; End.
39
![Page 40: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/40.jpg)
PROBLEMA 38.3.4Sa se scrie un program care afiseaza pe ecran numerele naturale mai mici sau egale cu n si divizibila cu t(n,t sunt numere na-turale,n<t).Numerele n,t ce citesc de la tastatura.
Program P3_4; Uses crt; Var i,n,t:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); Writeln('Introdu t:'); Readln(t); For i:=1 To n Do If i mod t=0 Then Writeln(i); Readkey; Readln; End.
40
![Page 41: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/41.jpg)
PROBLEMA 39.3.5Sa se scrie un program care calculeaza suma numerelor naturalea pare mai mici sau egale cu n.
Program P3_5; Uses crt; Var i,n:integer; s:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do If i mod 2=0 Then s:=s+i; Writeln(s:4:2); Readkey; Readln; End.
41
![Page 42: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/42.jpg)
PROBLEMA 40.3.6Sa se scrie un program care calculeaza suma numerelor naturale mai mici sau egale cu n care sunt divizibile cu 3.
Program P3_6; Uses crt; Var i,n:integer; s:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do If i mod 3=0 Then s:=s+i; Writeln(s:4:2); Readkey; Readln; End.
42
![Page 43: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/43.jpg)
PROBLEMA 41.3.7Sa se scrie un program care calculeaza cite numerelor naturale mai mici sau egale cu N sunt divizibile cu A.Numerele N si A se ci-tesc de la tastatura.
Program P3_7; Uses crt; Var i,n,a,t:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); Writeln('Introdu a:'); Readln(a); t:=0; For i:=1 To n Do If i mod a=0 Then t:=t+1; Writeln(t:5); Readkey; Readln; End.
43
![Page 44: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/44.jpg)
PROBLEMA 42.3.8Sa se scrie un program care calculeaza pro-dusul numerelor naturale impare mai mici sau egale cu N (N<=10).
Program P3_8; Uses crt; Var i,n:integer; p:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); p:=1; For i:=1 To n Do If i mod 2<>0 Then p:=p*i; Writeln(p:5:3); Readkey; Readln; End.
44
![Page 45: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/45.jpg)
PROBLEMA 43.3.9Se considera doua numere naturale X si N.Sa se scrie un program care calculeaza X^N.
Program P3_9; Uses crt; Var i,n,x:integer; p:real; Begin Clrscr; Writeln('Introdu n,x:'); Readln(n,x); P:=1; For i:=1 To n Do P:=P*x; Writeln(p:5:3); Readkey; Readln; End.
45
![Page 46: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/46.jpg)
PROBLEMA 44.3.10Se considera numarul natural N.Sa se scrie un program care :a) calculeaza suma si produsul divizorilor acestui numar;b) afiseaza divizorii numarului N si numarul acestora.
Program P3_10; Uses crt; Var i,n:integer; s,p:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; p:=1; For i:=1 To n Do If n mod i = 0 Then Begin
46
![Page 47: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/47.jpg)
s:=s+i; p:=p*i;Writeln(i); End; Writeln(s:5:3); Writeln(p:5:3); Readkey; Readln; End.
PROBLEMA 45.3.11Se considera o segventa de n(n<=100)numere intregi.Sa se scrie un program care calcu-leaza suma numerelor pozitive.
Program P3_11; Uses crt; Var i,n,x:integer; s:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do Begin Write('Introdu numerele:'); Read(x); If x>0 Then s:=s+x;
47
![Page 48: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/48.jpg)
End; Writeln('Raspuns'); Writeln(s:5:3); Readkey; Readln; End.
PROBLEMA 46.3.12Se considera o segventa de n(n<=100) numere reale. Sa se scrie un program care calculea-za cite numere sunt pozitive, cite numere sunt negative si cite numere sunt nule.
Program P3_12; Uses crt; Var i,n,k,l,j:integer;x:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); k:=0; l:=0; j:=0; For i:=1 To n Do Begin
48
![Page 49: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/49.jpg)
Write('Introdu numerele:'); Read(x); If x>0 Then k:=k+1; If x=0 Then l:=l+1; If x<0 Then j:=j+1; End; Writeln('Raspuns'); Writeln(k:5 ,l:5 ,j:5 ); Readkey; Readln; End.
PROBLEMA 47.3.13Se considera o segventa de n(n<=100)numere intregi.Sa se scrie un program care calcu-leaza media aritmetica a numerelor poziti-ve si media artimetica a numerelor negati-ve.
Program P3_13; Uses crt; Var i,n,x,k,l:integer; s1,s2,med1,med2 :real; Begin Clrscr; Writeln('Introdu n:');
49
![Page 50: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/50.jpg)
Readln(n); s1:=0; s2:=0; k:=0; l:=0; For i:=1 To n Do Begin Write('Introdu numerele:'); Read(x); If x>0 Then Begin k:=k+1; s1:=s1+x;End; If x<0 Then Begin l:=l+1; s2:=s2+x;End; End;med1:=s1/k;med2:=s2/l; Writeln('Raspuns'); Writeln(med1:5:3 ,med2:5:3); Readkey; Readln; End.
PROBLEMA 48.3.14Se considera o segventa de n(n<=100)numere reale.Sa se scrie un program care determina numarul minim .
Program P3_14; Uses crt; Var i,n:integer; min, x:real; Begin Clrscr; Writeln('Introdu n:');
50
![Page 51: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/51.jpg)
Readln(n); Writeln('Introdu primul numar:'); Readln(x); min:=x; For i:=2 To n Do Begin Write('Introdu numerele:'); Read(x); If x<min Then min:=x; End; Writeln('Raspuns'); Writeln(min:5:3); Readkey; Readln; End.
PROBLEMA 49.3.15Intr-o sera ,in fiecare zi,infloresc cu 15 flori mai multe decit in ziua precedenta. In prima zi au inflorit 10 flori.Sa se scrieun program care calculeaza cite flori au in-florit timp de o saptamina.
Program P3_15; Uses crt; Var i,s:integer;
51
![Page 52: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/52.jpg)
n:1..7; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=10; For i:=2 To n Do s:=s+15; Writeln('Raspuns'); Writeln(s:5); Readkey; Readln; End.
PROBLEMA 50.3.16Se se scrie un program care citeste de la tastatura o segventa de caractere si afi-seaza pe ecran:a)numarul cifrelor zecimale citite;b)numarul cifrelor pare;c)numarul cifrelor impare.
52
![Page 53: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/53.jpg)
Program P3_16; Uses crt; Var i,n,k,l,j:integer; x:char; Begin Clrscr; Writeln('Introdu n:'); Readln(n); k:=0; l:=0; j:=0; For i:=1 To n Do Begin Write('Introdu caracterele:'); Readln(x); case x of '0','2','4','6','8':l:=l+1; '1','3','5','7','9':j:=j+1; End; End; Writeln('Raspuns'); k:=l+j; Writeln(k:5);Writeln( l:5); Writeln( j:5 ); Readkey; Readln; End.
PROBLEMA 51.3.17Se considera o segventa de n(n<=100)numere intregi pozitive. Sa se scrie un program care atribuie unei variebilele valoarea TR-
53
![Page 54: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/54.jpg)
UE ,daca in acest sir exista cel putin un numar care se imparte la 7 fara rest in caz contrar-valoarea FALSE.
Program P3_17; Uses crt; Var i,n,x:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do Begin Writeln('Introdu numerele:'); Read(x); End; If x mod 7=0 Then Writeln('TRUE') Else Writeln('FALSE');
Readkey; Readln; End.
PROBLEMA 52.3.18
54
![Page 55: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/55.jpg)
Sa se scrie un program care calculeaza valorile functiei y=2x^2+7x pe segmentul [-2;8] a) cu pasul 1; b) cu pasul 0.5.
Program P3_18; Uses crt; Var x,y,h:real; Begin Clrscr; Writeln('Introdu pasul h:'); Readln(h); x:=-2; While x<=8 Do Begin y:=2*x*x+7*x; Writeln('y=',y); x:=x+h; End; Readkey; Readln; End.
55
![Page 56: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/56.jpg)
PROBLEMA 53.3.19Sa se scrie un program care afiseaza costul unei portiuni de cascaval de 50,100,150,..., 1000gr,daca se stie ca un kilogram costa 46lei 20bani.
Program P3_19; Uses crt; Var x,y:real; Begin Clrscr; x:=50; While x<=1000 Do Begin y:=0.04620*x; Writeln(y:2:2); x:=x+50; End; Readkey; Readln; End.
56
![Page 57: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/57.jpg)
PROBLEMA 54.3.20Un cetatean a depus la o Banca Comerciala 10000 lei. Sa se scrie un program care cal-culeaza suma pe care o va avea cetateanul peste 10 ani ,daca dobinda anuala este de 5% .
Program P3_20; Uses crt; Var x,y:real; Begin Clrscr; x:=1; While x<=10 Do Begin y:=10000*x; x:=x+0.05; End; Writeln(y:6:2); Readkey; Readln; End.
57
![Page 58: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/58.jpg)
PROBLEMA 55.3.21Un cetatean a depus la o Banca Comerciala o suma egala cu S lei cu dobinda de P%.Sa se un program care calculeaza peste cit ani suna se va mari cu cel mult 100%.
Program P3_21; Uses crt; Var s,p,h,x,t:real; Begin Clrscr; Writeln('Introdu s,p:'); Readln(s,p); x:=s; Repeat h:=s*x; x:=x+p/100; t:=h/10000000; Until x>100; Writeln(t:4:2); Readkey; Readln; End.
58
![Page 59: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/59.jpg)
PROBLEMA 56.3.22Se considera un numar natural n(n<=10).Sa se scrie un program care calculeaza : 1+1/2+1/4+...+1/(2n).
Program P3_22; Uses crt; Var s:real; i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do s:=s+1/i; Writeln(s:4:5); Readkey; Readln; End.
59
![Page 60: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/60.jpg)
PROBLEMA 57.3.23Se considera un numar natural n(n<=10).Sa se scrie un program care calculeaza: 1^2+2^2+3^2+4^2+...+n^2 .
Program P3_23; Uses crt; Var s:real; i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do s:=s+i*i; Writeln(s:5:3); Readkey; Readln; End.
60
![Page 61: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/61.jpg)
PROBLEMA 58.3.24Sa se scrie un program care calculeaza suma 1+1/2+2/3+3/4+...+N(N+1) ,pina cind va depasi valoarea 0.999.N este numar natural.
Program P3_24; Uses crt; Var s:real; i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); s:=0; For i:=1 To n Do Begin s:=s+i/(i+1); If s<0.999 Then Writeln(s:5:2) ; End; Readln; End.
61
![Page 62: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/62.jpg)
PROBLEMA 59.3.25De la tastatura se citesc numere intregi pozitive pina cind suma lor nu depaseste valoarea 1000.Sa se scrie un program carecalculeaza media artimetica a numerelor citi-te.
Program P3_25; Uses crt; Var suma,k,x,n,i:integer; med:real; Begin Clrscr; Writeln('Introdu n:'); Readln(n); suma:=0; For i:=1 To n Do Begin Writeln('Introdu numarul al',i,'- lea:'); Readln(x);
62
![Page 63: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/63.jpg)
If suma<1000 Then suma:=suma+x; End; Writeln('Suma numerelor este:',suma); med:=suma/n; Writeln('Media=',med:6:1); Readkey; Readln; End.
PROBLEMA 60.3.26Se considera o segvevta de numere :2, 7, 12, 17,... cu n termeni (n>=2).Sa se scrie un program care calculeaza suma termenilor pari
Program P3_26; Uses crt; Var suma,n,i,t:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); suma:=2; t:=2; For i:=1 To n-1 Do Begin t:=t+5; if t mod 2 =0 Then suma:=suma+t; End;
63
![Page 64: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/64.jpg)
Writeln('Suma numerelor este:',suma); Readkey; Readln; End.
PROBLEMA 61.3.27Se citesc 3 numere naturale n,p,k si o seg-venta de n numere naturale.Sa se scrie un program care calculeaza cite dintre acestea impartite la p dau restul k.
Program P3_27; Uses crt; Var s,n,i,p,x,k,t:integer; Begin Clrscr; Writeln('Introdu n,p,k:'); Readln(n,p,k); Writeln('Introdu primul numar:'); Readln(x); s:=0; t:=x;
64
![Page 65: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/65.jpg)
For i:=2 To n-1 Do Begin Writeln('Introdu numarul ',i,'-lea:'); Readln(x); t:=t+k; if t mod p =k Then s:=s+1; End; Writeln('Numarul ',s); Readkey; Readln; End.
PROBLEMA 62.3.34Sa se scrie un program care afiseaza primele 10 numere naturale, care fiind impartite la 5 si la 7 dau restul 2.
Program P3_34; Uses crt; Var i,t,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); t:=0; For i:=1 To n Do Begin If (i mod 5=2) and (i mod 7=2)
65
![Page 66: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/66.jpg)
Then Begin t:=t+1; If t<=10 Then Writeln(t:2 ,' ' ,i) End; End; Readkey; Readln; End.
PROBLEMA 63.3.35Sa se scrie un program care afiseaza urmatorul sir :zyyxxx...aaaaaa...a .
Program P3_35; Uses crt; Var i,j:char; Begin Clrscr; For i:='z' Downto 'a' Do For j:='z' Downto i Do
66
![Page 67: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/67.jpg)
Write(i); Readkey; Readln; End.
PROBLEMA 64.3.36Sa se scrie un program care afiseaza urmatorul triunghi : 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1.
Program P3_36;
67
![Page 68: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/68.jpg)
Uses crt; Var i,j,s,s1,s2:integer; Begin Clrscr; s:=0;s2:=0;s1:=0; For i:=1 To 5 Do Begin For j:=1 To i Do Write(i); Writeln; s1:=s1+i;end; s2:=s1+j; s:=s1+s2; Writeln(s:5, s1:5, s2:5); Readkey; Readln; End.
Programe cu tablouri unidimensionale
PROBLEMA 65.4.1Se considera A[1..n] de numere intregi , n<=100 .Sa se scrie un program care numara cite elemente pozitive contine acest tab-lou.
68
![Page 69: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/69.jpg)
Program P4_1; Uses crt; Var a:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i]>0 Then k:=k+1; Writeln('Numarul elementelor pozitive este:',k ); Readkey; Readln; End.
PROBLEMA 66.4.2Se considera A[1..n] cu elemente egale numai cu 1 sau 0,n<= 100.Sa se scrie un program ca-re numara cite zerouri si cite unitati conti-ne acest tablou.
69
![Page 70: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/70.jpg)
Program P4_2; Uses crt; Var a:array[1..100] of integer; k,l,i:integer; n:0..1; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0;l:=0; For i:=1 To n Do Begin If a[i]=0 Then k:=k+1 ; If a[i]=1 Then l:=l+1; End; Writeln('k=',k,' ','l=',l ); Readln; End.
PROBLEMA 67.4.3Se considera A[1..n] de numere intregi, n<= 100 .Sa se scrie un program care numara cite elemente pozitive sunt pe locuri pare.
70
![Page 71: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/71.jpg)
Program P4_3; Uses crt; Var a:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0;i:=2; While i<n Do Begin If a[i]>0 Then k:=k+1; i:=i+2; End; Writeln('k=',k ); Readkey; Readln; End.
PROBLEMA 68.4.4
71
![Page 72: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/72.jpg)
Se considera A[1..n] de numere intregi,n<= 100.Sa se scrie un program care numara cite elemente pozitive,cite negative si cite ele-mente nule contine acest tablou.
Program P4_4; Uses crt; Var a:array[1..100] of integer; k,l,z,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; l:=0; z:=0; For i:=1 To n Do Begin If a[i]>0 Then k:=k+1; If a[i]<0 Then l:=l+1; If a[i]=0 Then z:=z+1; End; Writeln('k=',k,' ','l=',l,' ','z=',z ); Readkey; Readln; End.
72
![Page 73: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/73.jpg)
PROBLEMA 69.4.5Se considera numarul natural M si tabloul A[1..n] de numere in tregi,n<=100.Sa se scrie un program care numara cite elemente din ta-blou sunt divizibile cu M.
Program P4_5; Uses crt; Var a:array[1..100] of integer; k,m,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu numarul m:'); Readln(m); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i] mod m = 0 Then k:=k+1; Writeln('Numarul elementelor divizibile cu m:',k ); Readkey; Readln; End.
73
![Page 74: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/74.jpg)
PROBLEMA 70.4.6Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care nu-mara cite elemente sunt diferite de:a) ultimul element;b) primul element.
Program P4_6; Uses crt; Var a:array[1..100] of integer; k,l,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; l:=0; For i:=1 To n Do Begin If a[i] mod a[1]=0 Then k:=k+1; If a[i] mod a[n]=0 Then l:=l+1; End; Writeln('k=',k,' ','l=',l ); Readkey; Readln; End.
74
![Page 75: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/75.jpg)
PROBLEMA 71.4.7Se considera A[1..n] de numere intregi, n<= 100. Sa se scrie un program care numara de cite ori figureaza in acest tablou elementul minim.
Program P4_7; Uses crt; Var a:array[1..100] of integer; k,i,n,min:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; min:=a[1]; For i:=1 To n Do If a[i]<min Then k:=k+1; Writeln('Num. de elemente minime:',k ); Readkey; Readln; End.
75
![Page 76: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/76.jpg)
PROBLEMA 72.4.8Informatia despre temperatura zilnica a lunii februarie a fost inscrisa intr-un tablou uni-dimensional.Sa se scrie un program care nu-mara de cite ori temperatura s-a coborit mai jos de zero grade.
Program P4_8; Uses crt; Var a:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i]<0 Then k:=k+1; Writeln('Numarul sub zero grade:',k ); Readkey; Readln;
76
![Page 77: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/77.jpg)
End.
PROBLEMA 73.4.9Se considera tabloul A[1..n] de numere int-regi,n<=100.Sa se scrie un program care nu-mara cite sunt sunt mai mari decit media ar-tmetica a tuturor elementelor.
Program P4_9; Uses crt; Var a:array[1..100] of integer; k,i,n,s:integer;media:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; s:=0; For i:=1 To n Do s:=s+i; media:=s/n; For i:=1 To n Do
77
![Page 78: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/78.jpg)
If a[i]>media Then k:=k+1; Writeln('Numarul elementelor mai mari decit media:',k ); Readkey; Readln; End.
PROBLEMA 74.4.10Se considera tabloul B[1..n] ,n<=24, in care au fost introdusa rezultatele muncii zilnice a unui lacatus in decursul unei perioade de n zile lucratoare.Sa se scrie un program care stabileste in cite zile lacatusul a indepli-nit norma zilnica k.
Program P4_10; Uses crt; Var b:array[1..24] of integer; k,i,n,l:integer; Begin Clrscr; Writeln('Intodu numarul zilelor n:'); Readln(n); Writeln('Introdu norma k:'); Readln(k); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(b[i]);
78
![Page 79: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/79.jpg)
End; Writeln; l:=0; For i:=1 To n Do If b[i]>=k Then l:=l+1; Writeln('Numarul zilelor ce indeplinesc norma :',l ); Readkey; Readln; End.
PROBLEMA 75.4.11Se considera tabloul A[1..15], in care au fost introduse rezul tatelor meciurilor cu participarea echipei de fotbal"PRUT".Elemente tabloului sunt egale cu "0", daca echipa "PRUT" a suferit infringere ;egal cu "1" ,daca meciul s-a terminat la egalitate;egale cu "3" ,daca a iesit invingatoare "PRUT" .Sa se scrie un program care stabiles-te in cite meciuri echipa "PRUT" a suferitinfringere ,in cite a iesit invingatoare si cite meciuri s-au terminat la egalitate.
Program P4_11; Uses crt; Var a:array[1..15] of integer; k1,k2,k3,i:integer;n:0..3; Begin Clrscr;
79
![Page 80: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/80.jpg)
Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; k1:=0; k2:=0; k3:=0; For i:=1 To n Do Begin If a[i]=0 Then k1:=k1+1; If a[i]=1 Then k2:=k2+1; If a[i]=3 Then k3:=k3+1; End;Writeln('Infringere :',k1); Writeln('Egal:',k2);Writeln('Victorii:',k3);End.
PROBLEMA 76.4.12Se considera tabloul Note[1..26],in care au fost introduse notele obtinute de elevii unei clase la lectia de informatica.Sa se scrie un program care numara notele de "8","9"si"10".
Program P4_12; Uses crt; Var a:array[1..100] of integer; k1,k2,k3,i,n:integer; Begin Clrscr; Writeln('Intodu numarul de note n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:');
80
![Page 81: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/81.jpg)
Readln(a[i]); End; Writeln; k1:=0; k2:=0; k3:=0; For i:=1 To n Do Begin If a[i]=8 Then k1:=k1+1; If a[i]=9 Then k2:=k2+1; If a[i]=10 Then k3:=k3+1; End; Writeln('Numarul de note de 8 :',k1); Writeln('Numarul de note de 9 :',k2); Writeln('Numarul de note de 10:',k3); Readkey; Readln; End.
PROBLEMA 77.4.13Se considera doua tablouri A[1..n] si B[1..n] de numere real, n<=100.Sa se scrie un program care numara pozitiile cu urmatoarea poprieta-tea) A[i]<B[i];b) A[i]=B[i];c) A[i]>B[i].
Program P4_13; Uses crt; Var a,b:array[1..100] of real; k1,k2,k3,i,n:integer; Begin
81
![Page 82: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/82.jpg)
Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu tabloului a:'); Readln(a[i]); End; Writeln; For i:=1 To n Do Begin Write('Introdu elementele tabloului b:'); Readln(b[i]); End; Writeln; k1:=0; k2:=0; k3:=0; For i:=1 To n Do Begin If a[i]<b[i] Then k1:=k1+1; If a[i]=b[i] Then k2:=k2+1; If a[i]>b[i] Then k3:=k3+1; End; Writeln('k1=',k1:5); Writeln('k2=',k2:5); Writeln('k3=',k3:5); Readln; End.PROBLEMA 78.4.14Se considera tabloul A[1..n] de numere in-tregi, n<=100. Sa se scrie un program care numara pozitiile pentru care A[i] nu este mai mic decit toate elementele premergatoare ale tabloului considerat(A[1],A[2],...,A[n-1).
Program P4_14; Uses crt; Var a:array[1..100] of integer; k,i,n:integer; Begin
82
![Page 83: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/83.jpg)
Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i+1]<a[i] Then k:=k+i; Writeln('k=',k ); Readkey; Readln; End.
PROBLEMA 79.4.15Se considera tabloul A[1..n] de numere pozi-tive, n<=100. Sa se scrie un program care calculeaza cite numere prime contine tablo-ul.
Program P4_15; Uses crt; Var a:array[1..100] of integer; k,i,n:integer;
83
![Page 84: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/84.jpg)
Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i] mod i=0 Then k:=k+1; Writeln('Numarul de numerele prime :',k ); Readkey; Readln; End.
PROBLEMA 80.4.16Se considera tabloul A[1..n] de numere in-tregi pozitive,n<=100. Sa se scrie un program de numarare a elementelor negative , nule si pozitive ale tabloului.
Program P4_16; Uses crt;
84
![Page 85: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/85.jpg)
Var a:array[1..100] of integer; k1,k2,k3,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k1:=0; k2:=0; k3:=0; For i:=1 To n Do Begin If a[i]<0 Then k1:=k1+1; If a[i]=0 Then k2:=k2+1; If a[i]>0 Then k3:=k3+1; End; Writeln('Numere negative :',k1 ); Writeln('Numere egale cu zero :',k2); Writeln('Numere pozitive :',k3); Readkey; Readln; End.
PROBLEMA 81.4.17Se considera tabloul X[1..n] de numere in-tregi nenule, n<=100. Sa se scrie un program care numara de cite ori se schimba semnul nu-merilor din acest tablou.
85
![Page 86: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/86.jpg)
Program P4_17; Uses crt; Var x:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu tabloului:',i,' '); Readln(x[i]); End; Writeln; k:=0; For i:=1 To n Do If x[i]*x[i+1]<0 Then k:=k+1; Writeln('Numarul de alternari :',k ); Readkey; Readln; End.
PROBLEMA 82.4.18Se considera tabloul X[1..n] de numere in-tregi nenule, n<=100. Sa se scrie un program
86
![Page 87: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/87.jpg)
care numara de cite ori se schimba semnul nu-merilor din acest tablou.
Program P4_18; Uses crt; Var x:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu tabloului:',i,' '); Readln(x[i]); End; Writeln; k:=0; For i:=1 To n Do If x[i]*x[i+1]<0 Then k:=k+1; Writeln('Numarul de alternari :',k ); Readkey; Readln; End.
PROBLEMA 83.4.19
87
![Page 88: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/88.jpg)
Se considera tabloul X[1..n] de numere in-tregi nenule n<=100. Sa se scrie un program care numara perechile de numere de pe pozitii consecutive modulul diferentei carora este egal cu 1.
Program P4_19; Uses crt; Var x:array[1..100] of integer; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(x[i]); End; Writeln; k:=0; For i:=1 To n Do If abs(x[i+1]-x[i])=1 Then k:=k+1; Writeln('Perechile de numere :',k ); Readkey; Readln; End.
88
![Page 89: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/89.jpg)
PROBLEMA 84.4.20Se considera tabloul A[1..n] de numere pozi-tive si negative, n<=100 . Sa se scrie un program care numara cite elemente il preced pe ultimul element negativ.
Program P4_20; Uses crt; Var a:array[1..100] of real; k,i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; k:=0; For i:=1 To n Do If a[i]<0 Then k:=n-i; Writeln('Numarul elementelor :',k ); Readkey; Readln; End.
89
![Page 90: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/90.jpg)
PROBLEMA 85.4.21Se considera tabloul A[1..n] de numere re-ale,n<=100. Sa se scrie un program care cal-culeaza suma si produsul tuturor elemente-lor.
Program P4_21; Uses crt; Var a:array[1..100] of real; i,n:integer; s,p:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; s:=0; p:=1; For i:=1 To n Do Begin s:=s+a[i]; p:=p*a[i]; End; Writeln('Suma :',s:5:3); Writeln('Produul :',p:5:3); Readkey; Readln; End.
90
![Page 91: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/91.jpg)
PROBLEMA 86.4.22Se considera tabloul A[1..n] de numere rea-le,n<=100. Sa se scrie un program care cal-culeaza produsul elementelor pozitive.
Program P4_22; Uses crt; Var a:array[1..100] of real; i,n:integer; p:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; p:=1; For i:=1 To n Do If a[i]>0 Then p:=p*a[i]; Writeln('Produul :',p:5:3); Readkey; Readln; End.
91
![Page 92: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/92.jpg)
PROBLEMA 87.4.23Se considera tabloul X[1..n] de numere in-tregi,n<=100. Sa se scrie un program care calculeaza suma elementelor de pe locurile pare si produsul elementelor de pe locurile impare.
Program P4_23; Uses crt; Var a:array[1..100] of real; i,n:integer; s,p:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('Introdu elementele tabloului:'); Readln(a[i]); End; Writeln; s:=0; p:=1; i:=0; While i<n Do Begin s:=s+a[i];
92
![Page 93: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/93.jpg)
i:=i+2; End; i:=1; While i<n Do Begin p:=p*a[i]; i:=i+2; End; Writeln('Suma :',s:5:3); Writeln('Produul :',p:5:3); Readln; End.PROBLEMA 88.4.24Se considera tabloul A[1..n] de numere in-tregi,n<=100. Sa se scrie un program care calculeaza media aritmetica a numerelor de pe locurile pare si media aritmetica a numerilor de pe locurile impare.
Program P4_24; Uses crt; Var a:array [1..100] of integer; i,n,s1,s2,k,l:integer; med1,med2:real; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; s1:=0; s2:=0;i:=1;k:=0;l:=0; While i<=n Do Begin s1:=s1+a[i];k:=k+1;
93
![Page 94: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/94.jpg)
i:=i+2; End; Writeln(s1:4);i:=2; While i<=n Do Begin s2:=s2+a[i];l:=l+1; i:=i+2; End; Writeln(s2:3); med1:=s1/k; med2:=s2/l; Writeln(med1:5:2,' ',med2:5:2); Readkey; Readln; End.
PROBLEMA 89.4.25Se considera tabloul A[1..n] de numere in-tregi, n<=100.Sa se scrie un program care calculeaza suma elementelor divizibilecu 5.
Program P4_25; Uses crt; Var a:array [1..100] of integer; i,n,s:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; s:=0; For i:=1 To n Do If a[i] mod 5 =0 Then s:=s+a[i];
94
![Page 95: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/95.jpg)
Writeln(s:5); Readkey; Readln; End.
PROBLEMA 90.4.26Se considera tabloul A[1..n] de numere in-tregi,n<=100. Sa se scrie un program care calculeaza suma elementelor pozitive de pe locurile pare.
Program P4_26; Uses crt; Var a:array [1..100] of integer; i,n,s:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End;
95
![Page 96: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/96.jpg)
s:=0; i:=2; While i<=n Do Begin If a[i]>0 Then s:=s+a[i]; i:=i+2; End; Writeln(s:3); Readkey; Readln; End.
PROBLEMA 91.4.27Se considera tabloul A[1..n] de numere in-tregi, n<=100.Sa se scrie un program care calculeaza suma elementelor divizibile cu 3 si cu 7.
Program P4_27; Uses crt; Var a:array [1..100] of integer; i,n,s:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']=');
96
![Page 97: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/97.jpg)
Readln(a[i]); End; s:=0; For i:=1 To n Do If (a[i] mod 3 =0) and (a[i] mod 7 =0) Then s:=s+a[i]; Writeln(s:5); Readkey; Readln; End.
PROBLEMA 92.4.28Se considera tabloul A[1..n] de numere in-tregi, n<=100. Sa se scrie un program care calculeaza suma elementelor mai mici ca ele-mentul maxim.
Program P4_28; Uses crt; Var a:array [1..100] of integer; i,n,s,max:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do
97
![Page 98: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/98.jpg)
Begin Write('a[',i,']='); Readln(a[i]); End; max:=a[1]; s:=0; For i:=1 To n Do If a[i]<max Then s:=s+a[i]; Writeln(s:5); Readkey; Readln; End.
PROBLEMA 93.4.29Se considera tabloul A[1..n] de numere in-tregi, n<=100 si un numar natural M.Sa se scrie un program care calculeaza suma ele-mentelor pozitive mai mici ca M. Daca nu exista astfel de numar sa se afiseze mesajul respectiv.
Program P4_29; Uses crt; Var a:array [1..100] of integer; i,n,s,m:integer; Begin
98
![Page 99: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/99.jpg)
Clrscr; Writeln('Introdu componentul n:'); Readln(n); Writeln('Introdu numarul natural m :'); Readln(m); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; s:=0; For i:=1 To n Do If a[i] mod m =0 Then s:=s+a[i]; Writeln(s:5); Readkey; Readln; End.
PROBLEMA 94.4.30Se considera tabloul A[1..n] de numere in-tregi diferite, n<=100. Sa se scrie un pro-gram care calculeaza suma:a) elementului maxim si elementului minim;b) elementelorcare se afla intre elementul maxim si elementul minim.
Program P4_30; Uses crt; Var a:array [1..100] of integer;
99
![Page 100: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/100.jpg)
i,n,s1,s2,min,max:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; s2:=0; min:=a[1]; max:=a[1]; For i:=1 To n Do Begin If a[i]<min Then min:=a[i]; If a[i]>max Then max:=a[i]; End; s1:=max+min; For i:=0 To n Do If( a[i]<max) and (a[i]>min) Then s2:=s2+a[i]; Writeln(s1:5); Writeln(s2:5); Readkey; Readln; End.
PROBLEMA 95.4.31Se considera tabloul A[1..n] de numere in-tregi, n<=100, unde se contine cel putin un numar negativ.Sa se scrie un program care calculeaza suma elementelo care se afla dupa primul element negativ.
Program P4_31; Uses crt;
100
![Page 101: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/101.jpg)
Var a:array [1..100] of integer; i,n,s,loc:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; s:=0; loc:=0; For i:=n Downto 1 Do If a[i]<0 Then loc:=i; Writeln(loc:5); For i:=1 To n Do s:=s+a[loc+i]; Writeln(s:5); Readkey; Readln; End.
PROBLEMA 96.4.32Se considera tabloul A[1..n] de numere in-tregi, n<=100.Sa se scrie un program care calculeaza suma elementelor divizibile cu 3;5 si 7.
Program P4_32;
101
![Page 102: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/102.jpg)
Uses crt; Var a:array [1..100] of integer; i,n,s:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; For i:=1 To n Do If (a[i] mod 3=0) and (a[i] mod 5=0) and (a[i] mod 7=0) Then s:=s+a[i]; Writeln(s:5); Readkey; Readln; End.
PROBLEMA 97.4.33Se considera doua tablouri A[1..15] si B[1.. 15] de numere reale.Sa se scrie un pro-gram care calculeaza produsul: (A[1]+B[15])*(A[2]+B[14])*..*(A[15]+B[1]).
102
![Page 103: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/103.jpg)
Program P4_33; Uses crt; Var a,b:array [1..100] of real; i,n:integer; p:real; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; For i:=1 To n Do Begin Write('b[',i,']='); Readln(b[i]); End; p:=1; For i:=1 To n Do p:=p*(a[i]+b[n+i-1]); Writeln(p:5:2); Readkey; Readln; End.
PROBLEMA 98.4.34Se considera tabloul A[1..n] de numere in-tregi, n<=100 . Sa se scrie un program care
103
![Page 104: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/104.jpg)
determina elementul maxim dintre elementele de pe locurile pare.
Program P4_34; Uses crt; Var a:array [1..100] of integer; i,n,max:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; max:=a[2]; i:=2; While i<=n Do Begin If a[i]>max Then max:=a[i]; i:=i+2; End; Writeln(max:5); Readkey; Readln; End.
PROBLEMA 99.4.35
104
![Page 105: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/105.jpg)
Se considera tabloul A[1..n] de numere in-tregi diferite, n<=100.Sa se scrie un program care determina:numarul mai mare si pozitia lui; numarul mai mic si pozitia lui.
Program P4_35; Uses crt; Var a:array [1..100] of integer; i,n,mare,mic,k,l:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; mare:=a[1]; For i:=1 To n Do If a[i]>mare Then Begin mare:=a[i]; k:=i; End; mic:=a[1]; For i:=1 To n Do If a[i]<mic Then Begin mic:=a[i]; l:=i; End; Writeln('mare=',mare,' ','k= ',k ); Writeln('mic=',mic,' ','l=',l ); Readkey; Readln; End.
105
![Page 106: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/106.jpg)
PROBLEMA 100.4.36Se considera numarul intreg X si tabloul A[1. .n] de numere intregi, n<=100.Sa se scrie un program care determina locurile pe care sunt elemente egale cu X.Se presupune ca in tablou exista cel putin un element egal cu X.
Program P4_26; Uses crt; Var a:array [1..100] of integer; i,n,x,k:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); Writeln('Introdu x:'); Readln(x); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; For i:=1 To n Do If a[i] =x Then Write(i:2); Readkey; Readln; End.
106
![Page 107: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/107.jpg)
PROBLEMA 101.4.37Se considera tabloul A[1..n] de numere in-tregi(cel putin un numar este negativ), n<= 100.Sa se scrie un program care determina lo-cul primului element negativ.
Program P4_37; Uses crt; Var a:array [1..100] of integer; i,n,k:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; k:=0; For i:=n Downto 1 Do If a[i] < 0 Then k:=i; Writeln(k:5); Readkey; Readln; End.
107
![Page 108: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/108.jpg)
PROBLEMA 102.4.38Se considera tabloul A[1..n] de numere in-tregi diferite, n<= 100.Sa se scrie un pro-gram care determina cel mai mare element ne-gativ.
Program P4_38; Uses crt; Var a,b:array [1..100] of integer; i,l,n,max,k:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End;k:=1; For i:=1 To n Do If a[i]<0 Then Begin b[k]:=a[i];k:=k+1; End; max:=b[1]; For l:=1 To k-1 Do If b[l]>max Then max:=b[l]; If k=1 Then Writeln('tabelul nu contine elemente negative') Else Writeln('max=',max); Readkey; Readln;
108
![Page 109: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/109.jpg)
End.
PROBLEMA 103.4.39Se considera tabloul A[1898..1998] care con-tine date despretemperatura medie a lunii februarie din perioada anillor 1898-1998.Fiex tempeeratura medie alunii februarie anul 1899.Sa se scrie un program care stebileste anul cind aceasta temperatura x a fost inre-gistrata ultima data. Daca o astfel de tem-peratura n-a fost inregistrata in perioada data, raspunsul va fi 0.
Program P4_39; Uses crt; Var a:array[1898..1998] of real; i,n,anul:integer; x:real; Begin Clrscr; Writeln('Intodu numarul de ani n:'); Readln(n); Writeln('Introdu media anului 1898='); Readln(x); For i:=1900 To n Do Begin Write('a [ ',i,']='); Readln(a[i]); End; Writeln; For i:=1900 To n Do
109
![Page 110: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/110.jpg)
If a[i]=x Then anul:=i; Writeln('Anul=',Anul); Readkey; Readln; End.
PROBLEMA 104.4.40Se considera tabloul A[1..n] de numere in-tregi,n<= 100. Sa se scrie un program care determina indicii a doua elemente suma ca-rora este maxima (adica cea mai mare dintre sumele perechilor posibile).
Program P4_40; Uses crt; Var a:array[1..100] of integer; i,j,n,k,l,max:integer; Begin Clrscr; Writeln('Intodu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a [ ',i,']='); Readln(a[i]); End; max:=a[1]+a[2]; Writeln; For i:=1 To n Do For j:=1 To n-1 Do If a[j]+a[j+1]>max Then max:=a[j]+a[j+1];
110
![Page 111: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/111.jpg)
Writeln(' max=',max); For i:=1 To n Do For j:=1 To n-1 Do If a[i]+a[j+1]=max Then Writeln('i=',i,' ','j=',j+1); Readkey;End.
PROBLEMA 105.4.41Se considera tabloul A[1..n] de numere in-tregi diferite, n<=100.Sa se scrie un program care determina elementul, ca valoare, de ele-mentul maxim.
Program P4_41; Uses crt; Var a:array[1..100] of integer; i,n,max:integer; Begin Clrscr; Writeln('Introdu componentul n='); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; max:=a[1]; For i:=1 to n do If a[i]>max Then max:=a[i]; Writeln('max=',max); For i:=1 To n Do
111
![Page 112: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/112.jpg)
If abs(a[i])=max Then Writeln('a[',i,']=',a[i]); Readkey; Readln; End.
PROBLEMA 106.4.42Se considera tabloul A[1..n] de numere in-tregi ,n<=100.Sa se scrie un program care de-termina cea mai lunga segventa de zerouri.
Program P4_42; Uses crt; Var a:array[1..100] of integer; i,n,k:integer; Begin Clrscr; Writeln('Introdu componentul n='); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; k:=0; For i:=1 to n do If (a[i]=0) And (a[i+1]=0) Then k:=k+1; Writeln('k=',k);
112
![Page 113: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/113.jpg)
Readkey; Readln; End.
PROBLEMA 107.4.43Se considera tabloul A[1..n] de numere in-tregi si un numar natural k ,n<=100,k<=n. Sa se scrie un program care determina daca exis-ta o segventa de k elemente de pozitii conse-cutive ale caror valoare sa fie egala cu 0.
Program P4_43; Uses crt; Var a:array[1..100] of integer; i,n,k,l:integer; Begin Clrscr; Writeln('Introdu componentul n='); Readln(n); Writeln('Introdu segventa k='); Readln(k); For i:=1 To n Do Begin Write('a[',i,']=');
113
![Page 114: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/114.jpg)
Readln(a[i]); End; l:=0; For i:=1 to n do If a[i]=a[i+1] Then l:=l+1; Writeln('l=',l); If l=k Then Writeln('DA') Else Writeln('NU'); Readkey; Readln; End.
PROBLEMA 108.4.44Se considera tabloul X[1..n] de numere in-tregi,n<=100. Sa se scrie un program care de-termina lungimea celei mai lungi segvente de elemente ordonate crescator.
Program P4_44; Uses crt; Var x:array [1..100] of integer; i,n,k,nmax:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']=');
114
![Page 115: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/115.jpg)
Read(x[i]); End; k:=1; nmax:=0; For i:=1 To n Do If x[i]=x[i+1]-1 Then k:=k+1 Else Begin If k>nmax Then nmax:=k; k:=1; End; If k>nmax Then nmax:=k; Write('Cea mai lunga segventa de elemente orgonate '); Writeln(nmax,' termeni'); Readkey; Readln; End.
PROBLEMA 109.4.45Intr-un grup de n persoane fiecare isi decla-ra virsta spunind un numar:anii.Sa se scrie un program care afiseaza virsta pe care oau cele mai multe persoane in grup.
Program P4_45; Uses crt; Var x:array [1..100] of integer; i,n,k,nmax:integer; Begin Clrscr; Write('Cite persoane sunt n='); Readln(n); For i:=1 To n Do
115
![Page 116: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/116.jpg)
Begin Write('a[',i,']='); Read(x[i]); End; k:=1; nmax:=0; For i:=1 To n Do Begin If x[i]=x[i+1] Then k:=k+1 Else Begin If k>nmax Then nmax:=k; k:=1; End; If k>nmax Then Begin nmax:=k; Writeln(x[i]); End; End; Write('Cea mai lunga segventa de elemente egale are '); Writeln(nmax,' termeni'); Readln; End.PROBLEMA 110.4.46Se considera tabloul A[1..n] de numere in-tregi,in care unele valori se pot repeta.Sa se scrie un program care determina elementul care se repeta cel mai des.Daca sunt citeva elemente de acest,atunci sa se indice unul dintre ele.
Program P4_46; Uses crt; Var a:array [1..100] of integer; i,j,n,k,nmax:integer; Begin
116
![Page 117: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/117.jpg)
Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; k:=1; nmax:=0; For i:=1 To n Do For j:=2 To n Do Begin If a[i]=a[j] Then k:=k+1 Else Begin If k>nmax Then nmax:=k; k:=1; End; If k>nmax Then Writeln(a[i]); End; Readkey; Readln; End.PROBLEMA 111.4.47Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care afi-seaza mai intii elementele nenule,apoi cele nule.
Program P4_47; Uses crt; Var a:array[1..100] of integer; i,j,n,l:integer; Begin
117
![Page 118: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/118.jpg)
Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln; l:=0; For i:=1 To n Do If (a[i]>0) or (a[i]<0) Then Begin Write(a[i],' '); l:=l+1; End; For i:=1 To n Do If a[i]=0 Then Write(a[n-i+l+3],' '); Readkey; Readln; End.
PROBLEMA 112.4.48Se considera tabloul X[1..n] de numere in-tregi,n<=100.Sa se scrie un program care afi-seaza numerele pozitive,apoi cele negative si la sfirsit cele nule.
Program P4_48; Uses crt;
118
![Page 119: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/119.jpg)
Var x:array[1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('x[',i,']='); Readln(x[i]); End; Writeln; For i:=1 To n Do If x[i]>0 Then Write(x[i],' '); For i:=1 To n Do If x[i]<0 Then Write(x[i],' '); For i:=1 To n Do If x[i]=0 Then Write(x[i],' '); Readln; End.
PROBLEMA 113.4.49Se considera tabloul X[1..n] format din nu-mere de 0,1 sau 2,n<=100. Sa se scrie un pro-gram care afiseaza mai intii numerele egale
119
![Page 120: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/120.jpg)
cu 1, apoi egale cu 2 si la sfirsit cele ega-le cu 0.
Program P4_49; Uses crt; Var x:array[1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('x[',i,']='); Readln(x[i]); End; Writeln; For i:=1 To n Do If x[i]=1 Then Write(x[i],' '); For i:=1 To n Do If x[i]=2 Then Write(x[i],' '); For i:=1 To n Do If x[i]=0 Then Write(x[i],' '); Readln; End.
PROBLEMA 114.4.50
120
![Page 121: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/121.jpg)
Se considera tabloul A[1..2n] de numere in-tregi,n<=50.Sa se scrie un program care afi-seaza intr-o linie primele n elemente, iar in alta linie urmaroarele n elemente.
Program P4_50; Uses crt; Var x:array[1..100] of integer; i:integer; n:1..50; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To 2*n Do Begin Write('x[',i,']='); Readln(x[i]); End; Writeln; For i:=1 To n Do Write(x[i],' '); Writeln; For i:=n+1 To 2*n Do Write(x[i],' '); Readln; End.
121
![Page 122: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/122.jpg)
PROBLEMA 115.4.51Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care afi-seaza: in prima linie numerele pozitive; in a doua linie numarul elementelor pozitive; in a treia linie numerele negative; in a patra li-nie numarul elementelor negative.
Program P4_51; Uses crt; Var a:array[1..100] of integer; i,n,k,l:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln;k:=0; For i:=1 To n Do If a[i]>0 Then Begin Write(a[i],' '); k:=k+1; End;Writeln; Writeln(k);l:=0; For i:=1 To n Do If a[i]<0 Then Begin Write(a[i],' '); l:=l+1; End;Writeln; Writeln(l);
122
![Page 123: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/123.jpg)
Readln; End.
PROBLEMA 116.4.52Se considera tabloul A[1..n] de numere natu-rale,n<=100.Sa se scrie un program care afi-seaza divizorii fiecarui element din tablou. Rezultatul se va afisa in forma:elenemtul di-vizorii .
Program P4_52; Uses crt; Var a:array[1..100] of integer; i,j,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln; For i:=1 To n Do Begin Writeln('a[',i,'] divizorii '); For j:=1 To n Do Begin If a[i] mod j=0 Then Writeln(j,' ' ); End; End; Readln;
123
![Page 124: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/124.jpg)
End.
PROBLEMA 117.4.53Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care in-locuieste elementele mai mari ca 10 cu patra-tul lor.
Program P4_53; Uses crt; Var a:array[1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln; For i:=1 To n Do Begin If a[i]>10 Then Write(a[i]*a[i],' ') ; If a[i]<=10 Then Write(a[i],' '); End; Readkey; Readln; End.
124
![Page 125: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/125.jpg)
PROBLEMA 118.4.54Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care ma-reste fiecare element cu 5.
Program P4_54; Uses crt; Var a:array[1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln; For i:=1 To n Do Write(a[i]+5,' '); Readkey; Readln; End.
125
![Page 126: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/126.jpg)
PROBLEMA 119.4.55Se considera tabloul A[1..n] de numere in-tregi,n<=100.Sa se scrie un program care in-locuieste de pe locurile impare cu 100.
Program P4_55; Uses crt; Var a:array[1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; Writeln; i:=1; While i<=n Do Begin a[i]:=100; Write(a[i],' ') ; Write(a[i+1],' ');
126
![Page 127: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/127.jpg)
i:=i+2; End; Readkey; Readln; End.
PROBLEMA 120.4.56Se considera tabloul A[1..n] de numere in-tregi distincte,n<=100. Sa se scrie un pro-gram care efectuiaza interschimbarea elemen-tului maxim cu elementul minim.
Program P4_56; Uses crt; Var a:array [1..100] of integer; i,n,k,q,min,max:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; max:=a[1];min:=a[1]; For i:=1 To n Do Begin
127
![Page 128: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/128.jpg)
If a[i]>=max Then Begin max:=a[i]; k:=i; End; If a[i]<=min Then Begin min:=a[i]; q:=i; End; End; a[k]:=min; a[q]:=max; For i:=1 To n Do Write(a[i],' '); Readkey; Readln; End.PROBLEMA 121.4.57Se considera tabloul A[1..n] de numere in-tregi ,n<=100 si un numar intreg X.Sa se scrie un program care modifica elementele acestui tablou ,adaugind la elementele de pe locurile pare numarul X.
Program P4_57; Uses crt; Var a:array [1..100] of integer; i,n,x:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Readln(x); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End;
128
![Page 129: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/129.jpg)
i:=2; Write(a[1],' '); While i<=n Do Begin Write(a[i]+x,' '); Write(a[i+1],' '); i:=i+2; End; Readkey; Readln; End.
PROBLEMA 122.4.58Se considera tabloul A[1..n] de numere rea-le,n<=100. Sa se scrie un program care modi-fica tabloul in felul urmator :elementele mi-nime le inlocuieste cu media aritmetica a tu-turor elementelor,iar elementele maxime-cu suma elementelor pozitive.
Program P4_58; Uses crt; Var a:array [1..100] of real; i,n,k,q:integer; s1,s,s2,max,min:real; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do
129
![Page 130: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/130.jpg)
Begin Write('a[',i,']='); Read(a[i]); End; max:=a[1];min:=a[1]; s:=0; s2:=0; For i:=1 To n Do Begin If a[i]>=max Then Begin max:=a[i]; k:=i; End; If a[i]<=min Then Begin min:=a[i]; q:=i; End; s:=s+a[i]; If a[i]>0 Then s2:=s2+a[i]; End; s1:=s/n; a[k]:=s2; a[q]:=s1; For i:=1 To n Do Write(a[i]:5:2,' '); Readkey; Readln; End.PROBLEMA 123.4.59Se considera tabloul A[1..n] de numere reale ,n<=100. Sa se scrie un program care modifica tabloul in felul urmator: elementele negative le inlocuieste cu elementul maxim, elementele pozitive-cu media aritmetica a tuturor ele-mentelor,iar elementele nule-cu 100.
Program P4_59; Uses crt; Var a:array [1..100] of real; i,n,k:integer; s,max,s1:real; Begin Clrscr; Write('Cite elemente are tabloul n=');
130
![Page 131: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/131.jpg)
Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; max:=a[1]; For i:=1 To n Do Begin If a[i]>=max Then Begin max:=a[i]; k:=i; End; s:=s+a[i]; End;s1:=s/n; For i:=1 To n Do Begin If a[i]<0 Then Write(max:5:2,' '); If a[i]>0 Then Write(s1:5:2,' '); If a[i]=0 Then Write(100,' '); End; Readkey; Readln; End.PROBLEMA 124.4.60Se considera tabloul A[1..n] de numere in-tregi, n<=100.Sa se scrie un program care mo-difica tabloul in felul urmator:elementele pozitive le inlocuieste cu 1,cele negative-cu patratul lor,iar cele nule-cu 7.
Program P4_60; Uses crt; Var a:array [1..100] of integer; i,n,k,q,min,max:integer; Begin Clrscr; Write('Cite elemente are tabloul n=');
131
![Page 132: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/132.jpg)
Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; For i:=1 To n Do Begin If a[i]>0 Then Write(1,' '); If a[i]<0 Then Write(a[i]*a[i],' '); If a[i]=0 Then Write(7,' '); End; Readkey; Readln; End.
PROBLEMA 125.4.61Se considera tabloul A[1..10] de numere in-tregi,n<=100. Sa se scrie un program care mo-difica tabloul, scriind in ordine inversa elementele din prima jumatate a tabloului, apoi in ordine inversa elementele din juma-tatea a doua a tabloului:A[5],A[4],A[3],A[2],A[1],A[10],A[9], A[8],A[7],A[6].
Program P4_61; Uses crt;
132
![Page 133: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/133.jpg)
Var a:array [1..10] of integer; i,n:integer; Begin Clrscr; Writeln('Introdu n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; For i:=n div 2 Downto 1 Do Write(a[i],' '); For i:=n Downto n div 2+1 Do Write(a[i],' '); Readkey; Readln; End.
PROBLEMA 126.4.62Se considera tabloul A[1..n] (n-numar par) de numere intregi,n<=100. Sa se modifice acest tablou, schimbind primul element cu al doilea ,al treilea element cu al patrulea,s.a.m.d...
Program P4_62; Uses crt; Var a:array [1..100] of integer;
133
![Page 134: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/134.jpg)
i,n,k,q,min,max:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; For i:=1 To n Do Begin a[i]:=a[i+1]; Write(a[i],' '); i:=i+1; End; Readkey; Readln; End.
PROBLEMA 127.4.63Se considera tabloul A[1..n] de numere in-tregi, n<=100. Sa se scrie un program care efectuiaza deplasarea spre stinga cu o po-zitie a ele mentelor A[2],A[3],...,A[n]. Pri-mul element va fi scris pe ultima pozitie.
134
![Page 135: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/135.jpg)
Program P4_63; Uses crt; Var a:array [1..100] of integer; i,k,n,m:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n);Readln(m);
Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; For i:=m To n-m Do Begin a[i]:=a[i+1]; Write(a[i],' ');
End; Write(a[m],' ') For i:=1 To m-3 Do Begin a[i]:=a[i+1]; Write(a[i],' '); End; Readkey; Readln; End.PROBLEMA 128.4.64Se considera tabloul A[1..n] de numere in-tregi, n<=100. Sa se scrie un program care efectuiaza deplasarea spre stinga cu o po-
135
![Page 136: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/136.jpg)
zitie a elementelor A[2],A[3],...,A[n].Primul element va fi scris pe ultima pozitie.
Program P4_64; Uses crt; Var a:array [1..100] of integer; i,k,n:integer; Begin Clrscr; Write('Cite elemente are tabloul n='); Readln(n); Writeln('Dati',n,'numere intregi:'); For i:=1 To n Do Begin Write('a[',i,']='); Read(a[i]); End; Write(a[2],' '); For i:=2 To n-1 Do Begin a[i]:=a[i+1]; Write(a[i],' ');
End; Write(a[i-n+2],' '); Readkey; Readln; End.
PROBLEMA 129.4.65
136
![Page 137: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/137.jpg)
Se considera tabloul X[1..10] de numere in-tregi egale numai cu 0,1 sau 2. Sa se scrie un program care aranjeaza pe primele locuri elementele egale cu 1, apoi cele egale cu 0, apoi cele egale cu 2.
Program P4_65; Uses crt; Var x:array [1..10] of integer; i,n:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('x[',i,']='); Readln(x[i]); End; For i:=1 To n Do If x[i]=1 Then Write(x[i],' '); For i:=1 To n Do If x[i]=0 Then Write(x[i],' '); For i:=1 To n Do If x[i]=2 Then Write(x[i],' '); Readkey; Readln; End.
137
![Page 138: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/138.jpg)
PROBLEMA 130.4.66Se considera tabloul A[1..n] de numere in-tregi pozitive,n<=100. Sa se scrie un program care modifica tabloul in felul urmator:ele-mentele egale cu 2 le inlocuieste cu 4,ele-mentele egale cu 4 le inlocuieste cu 8, iar elementele egale cu 8 le inlocuieste cu 2.
Program P4_66; Uses crt; Var a:array [1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; For i:=1 To n Do If a[i]=2 Then Write('a[',i,']=4, '); For i:=1 To n Do If a[i]=4 Then Write('a[',i,']=8, '); For i:=1 To n Do If a[i]=8 Then Write('a[',i,']=2, '); Readkey; Readln; End.
138
![Page 139: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/139.jpg)
PROBLEMA 131.4.67Se considera tabloul A[1..n] de numere in-tregi ,n<=100.Sa se scrie un program care or-doneaza descrescator elementele acestui ta-blou.
Program P4_67; Uses crt; Var a:array [1..100] of integer; i,j,aux,n:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Begin Write('a[',i,']='); Readln(a[i]); End; For i:=1 To n-1 Do For j:=1 To n-1 Do If a[j]<a[j+1] Then Begin aux:=a[j]; a[j]:=a[j+1]; a[j+1]:=aux; End; Write('Tabloul ordonat:'); For i:=1 To n Do Write(a[i],' '); Readkey; Readln; End.
139
![Page 140: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/140.jpg)
PROBLEMA 132.4.68Se considera numarul natural N format din cel mult 9 cifre.Sa se scrie un program care in-scrie in tabloul unidimensional B,divizorii numarului N.
Program P4_68; Uses crt; Var b:array [1..100] of integer; i,j,n:integer; Begin Clrscr; Writeln('Introdu numarul n:'); Readln(n); For i:=1 To n Do If n mod i=0 Then Begin b[i]:=i; Write(i,' ' ); End; Readkey; Readln; End.
140
![Page 141: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/141.jpg)
PROBLEMA 133.4.69Sa se scrie un program care creaza un tablou A[1..n] ,n<=100,dina) numere naturale in ordine crescatoare (1,2,...,n)b) numerele naturale in ordine descrescatoare (n,n-1,...,1).
Program P4_69; Uses crt; Var a:array [1..100] of integer; i,n:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); For i:=1 To n Do Write('a[',i,']=',i,' '); Writeln; For i:=n Downto 1 Do Write('a[',i,']=',i,' '); Readkey; Readln; End.
141
![Page 142: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/142.jpg)
Programe cu tablouri bidimensionale
PROBLEMA 134.5.1Se considera tabloul A[1..n,1..m] de numere intregi,n,m<=20.Sa se scrie un program care calculeaza suma si produsul elementelor po-zitive.
Program P5_1; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,s,p:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin Write('a[',i,',',j,']='); Read(a[i,j]); End; s:=0; p:=1;
142
![Page 143: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/143.jpg)
For i:=1 To n Do For j:=1 To m Do If a[i,j]>0 Then Begin s:=s+a[i,j]; p:=p*a[i,j]; End; Writeln('s=',s); Writeln('p=',p); Readkey; Readln; End.PROBLEMA 135.5.2Se considera tabloul A[1..n,1..m] de numere intregi,unde n, m<=20. Sa se scrie un program care determina numarul elementelor mai maridecit media aritmetica a tuturor lementelor.
Program P5_2; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,s,k:integer; s1:real; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin Write('a[',i,',',j,']='); Read(a[i,j]); End; s:=0; For i:=1 To n Do For j:=1 To m Do
143
![Page 144: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/144.jpg)
s:=s+a[i,j]; s1:=s/(n+m); k:=0; For i:=1 To n Do For j:=1 To m Do If a[i,j]>s1 Then k:=k+1; Writeln('k=',k); Readkey; Readln; End.
PROBLEMA 136.5.3Se considera tabloul A[1..n,1..m] de numere intregi,unde n, m<=20. Sa se scrie un program care determina elementul maxim.
Program P5_3; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,max:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin Write('a[',i,',',j,']='); Read(a[i,j]); End; max:=a[1,1]; For i:=1 To n Do
144
![Page 145: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/145.jpg)
For j:=1 To m Do If a[i,j]>max Then max:=a[i,j]; Writeln('max=',max); Readkey; Readln; End.
PROBLEMA 137.5.4Se considera tabloul A[1..n,1..m] de numere intregi,unde n, m<=20. Sa se scrie un program care determina elementul minim si pozitia lui.
Program P5_4; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,min:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin Write('a[',i,',',j,']='); Read(a[i,j]);
145
![Page 146: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/146.jpg)
End; min:=a[1,1]; For i:=1 To n Do For j:=1 To m Do If a[i,j]<min Then min:=a[i,j]; For i:=1 To n Do For j:=1 To m Do If a[i,j]=min Then Write('a[',i,',',j,']',' '); Writeln; Writeln('min=',min); Readkey; Readln; End.
PROBLEMA 138.5.5Se considera tabloul Y[1..n,1..m] de numere intregi,unde n, m<=20. Sa se scrie un program care determina elementul minim si elemen-tulmaxim, precum si pozitiile acestora.
Program P5_5; Uses crt; Var y:array [1..20,1..20] of integer; i,j,n,m,min,max,k,l:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin
146
![Page 147: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/147.jpg)
Write('y[',i,',',j,']='); Read(y[i,j]); End; min:=y[1,1]; max:=y[1,1]; For i:=1 To n Do For j:=1 To m Do Begin If y[i,j]<min Then min:=y[i,j]; If y[i,j]>max Then max:=y[i,j]; End; Writeln('max=',max,' ' ,'min=',min); For i:=1 To n Do For j:=1 To m Do Begin If y[i,j]=max Then Write('y[',i,',',j,']',' '); If y[i,j]=min Then Write('y[',i,',',j,']',' '); End; Readln; End.PROBLEMA 139.5.6Se considera tabloul A[1..n,1..n] de numere intregi,unde n, m<=20. Sa se scrie un program care determina elementul maxim de pe diago-nala principala si elementul maxim de pe di-agonala secundara.
Program P5_6; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,max1,max2:integer; Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); Writeln('Introdu un tablou cu ',n,'linii
147
![Page 148: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/148.jpg)
si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); max1:=a[1,1];max2:=a[1,n]; For i:=1 To n Do If a[i,i]>max1 Then max1:=a[i,i]; For j:=n Downto 1 Do For i:=1 To n Do If a[i,j]>max2 Then max2:=a[i,j]; Writeln('max1=',max1); Writeln('max2=',max2); Readkey; Readln; End.
PROBLEMA 140.5.7Se considera tabloul A[1..n,1..n] de numere intregi,unde n, m<=20. Sa se scrie un program care zerografiaza diagonala principala .
Program P5_7; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n:1..20; Begin Clrscr; Write('Introdu componentul n:'); Readln(n); For i:=1 To n Do
148
![Page 149: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/149.jpg)
For j:=1 To n Do Begin Write('a[',i,',',j,']='); Read(a[i,j]); End; For i:=1 To n Do a[i,i]:=0; Writeln ('Tabloul cu diagonala principala zerografiata:'); For i:=1 To n Begin For j:=1 To n Do Write(a[i,j]:4); Writeln End; Readkey; Readln; End.
PROBLEMA 141.5.8Se considera tabloul A[1..n,1..n] de numere intregi,n<=20.Sa se scrie un program care schimba in opus semnele elementelor situate deasupra diagonalei principale.
Program P5_8; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n:integer; Begin Clrscr;
149
![Page 150: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/150.jpg)
Writeln('Introdu componentul n:'); Readln(n); Writeln('Introdu un tablou cu ',n,'linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For i:=1 To n Do For j:=i+1 To n Do a[i,j]:=-a[i,j]; Writeln; For i:=1 To n Do Begin For j:=1 To n Do Write(a[i,j]:4); Writeln; End; Readkey; Readln; End.
PROBLEMA 142.5.9Se considera tabloul A[1..n,1..n] de numere intregi,n<=20.Sa se scrie un program care zerografiaza elementele de pe diagonala se-cundara si cele mai jos de ea.
Program P5_9; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n:integer;
150
![Page 151: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/151.jpg)
Begin Clrscr; Writeln('Introdu componentul n:'); Readln(n); Writeln('Introdu un tablou cu ',n,'linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For j:=n Downto 1 Do For i:=n Downto n-j+1 Do Begin a[i,j]:=0; Writeln; End; For i:=1 To n Do Begin For j:=1 To n Do Write(a[i,j]:4); Writeln; End; Readkey; Readln; End.
PROBLEMA 143.5.10Se considera tabloul A[1..n,1..n] de numere intregi,n<=20.Sa se scrie un program care zerografiaza elementele de pe diagonala secundara si cele mai jos de ea.
Program P5_10; Uses crt;
151
![Page 152: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/152.jpg)
Var a:array [1..20,1..20] of integer; b:array [1..40] of integer; i,j,k,n,m:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); For i:=1 To n Do For j:=1 To m Do Begin If a[i,j]>0 Then Begin b[i]:=a[i,j]; Write(b[i]:4); End; End; Readkey; Readln; End.
PROBLEMA 144.5.11Se considera tabloul A[1..n,1..m] de numere intregi,n, m<=20. Sa se scrie un program care calculeaza numarul de elemente pozitive de pediagonala principala.
152
![Page 153: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/153.jpg)
Program P5_11; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,k:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); k:=0; For i:=1 To n Do If a[i,i]>0 Then k:=k+1; Writeln('k=',k); Readkey; Readln; End.
PROBLEMA 145.5.12O tara are 50 orase, legate prin comunicatii aeriene. Costul unui bilet din orasul i in orasul j e indicat in tabloul bidimensional.
153
![Page 154: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/154.jpg)
Pretul [1..50,1..50]. Sa se scrie un program care gaseste o ruta din orasul i in orasul j cu cel mai mic pret.
Program P5_12; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,mic:integer; Begin Clrscr; Writeln('Introdu componentele n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,'linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Begin Write('a[',i,',',j,']='); Read(a[i,j]); End; mic:=a[1,1]; For i:=1 To n Do For j:=1 To m Do If a[i,j]<mic Then mic:=a[i,j]; For i:=1 To n Do For j:=1 To m Do If a[i,j]=mic Then Write('a[',i,',',j,'],',' '); Readkey; Readln; End.
PROBLEMA 146.5.13
154
![Page 155: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/155.jpg)
Se considera tabloul A[1..n,1..n] de numere intregi,n, m<=20. Sa se scrie un program care determina elementul minim si elementul maximdintre elementele care se afla mai jos de di-agonala principala si sa se efectuieze inter-schimbarea lor.
Program P5_13; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,k,s,p,l,x,max,min:integer; Begin Clrscr; Writeln('Introdu componentele n:'); Readln(n); Writeln('Introdu un tablou cu ',n,'linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); max:=a[n,1]; min:=a[n,1]; For i:=n Downto 2 Do For j:=1 To i-1 Do Begin If a[i,i]>=max Then Begin max:=a[i,j]; k:=i; s:=j; End; If a[i,j]<=min Then Begin min:=a[i,j]; l:=i; p:=j; End; End; writeln('max=',max,', ''min=',min); a[k,s]:=min; a[l,p]:=max; For i:=1 To n Do Begin For j:=1 To n Do Write(a[i,j],' '); Writeln; End; Readln;
155
![Page 156: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/156.jpg)
End.PROBLEMA 147.5.14Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20. Sa se scrie un program care calculeaza suma elementelor care nu se afla pe diagonala secundara.
Program P5_15; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,s:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu un tablou cu ',n,',linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); Writeln; s:=0; For i:=1 To n Do s:=s+a[i,i]; Writeln('s=',s); For i:=1 To n Do Begin For j:=1 To n Do Write(a[i,j]+s:4); Writeln; End; Readkey; Readln; End.
156
![Page 157: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/157.jpg)
PROBLEMA 148.5.15Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20. Sa se scrie un program care calculeaza suma elementelor care nu se afla pe diagonala secundara.
Program P5_15; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,s,s1,s2:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu un tablou cu ',n,',linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); Writeln; s:=0; For i:=1 To n Do For j:=1 To n Do s:=s+a[i,j]; Writeln('s=',s); s1:=0; For i:=1 To n Do s1:=s1+a[i,n+1-i]; Writeln('s1=',s1); s2:=s-s1; Writeln('s2=',s2); Readkey;
157
![Page 158: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/158.jpg)
Readln; End.
PROBLEMA 149.5.16Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20. Sa se scrie un program care calculeaza media aritmetica a elemente-lor de diagonala principala si suma ele-mentelor de pe diagonala secundara.
Program P5_16; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,s,s1:integer; media:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu un tablou cu ',n,',linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); Writeln; s:=0; For i:=1 To n Do s:=s+a[i,i]; Writeln('s=',s); media:=s/n; Writeln('media=',media:5:2); s1:=0; For i:=1 To n Do s1:=s1+a[i,n+1-i];
158
![Page 159: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/159.jpg)
Writeln('s1=',s1); Readkey; Readln; End.
PROBLEMA 150.5.17Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care determina numarul elementelor nenule de pe fiecare linie.
Program P5_17; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,k:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,',linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For i:=1 To n Do Begin k:=0; For j:=1 To m Do If a[i,j]>0 Then k:=k+1; Writeln('Numarul elementelor pozi- tive de pe linia ',i,'este:',k);
159
![Page 160: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/160.jpg)
End; Readkey; Readln; End.
PROBLEMA 151.5.18Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care calculeaza suma si produsul elementelor de pe fiecare linie.
Program P5_18; Uses crt; Var a:array [1..20,1..20] of integer; b:array [1..20] of integer; i,j,n,m,s,p:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For i:=1 To n Do Begin s:=0; p:=1; For j:=1 To m Do
160
![Page 161: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/161.jpg)
Begin s:=s+a[i,j]; p:=p*a[i,j]; End;Writeln('Suma elementelor de pe linia ',i,' este:',s);Writeln('Produsul elementelor de pe linia ',i,'este:',p);End; Readkey;Readln;End.PROBLEMA 152.5.19Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20. Sa se scrie un program care creaza un vector din elementele diago-nalei principale.
Program P5_19; Uses crt; Var a:array [1..20,1..20] of integer; b:array [1..20] of integer; i,j,n:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu un tablou cu ',n,', linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); Writeln; For i:=1 To n Do Begin b[i]:=a[i,i];
161
![Page 162: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/162.jpg)
Write(b[i]:4); End; Readkey; Readln; End.
PROBLEMA 153.5.20Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care creaza un tablou B[1..n] din sumele ele-mentelor de pe linii din tabloul A.
Program P5_20; Uses crt; Var a:array [1..20,1..20] of integer; b:array [1..20] of integer; i,j,n,m,s:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln;
162
![Page 163: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/163.jpg)
For i:=1 To Readkey; Readln; End.
PROBLEMA 154.5.21Se considera tabloul A[1..n,1..m] de numere reale,unde n,m<=20. Sa se scrie un program care creaza un tablou B[1..m] din produsul elementelor de pe coloane din tabloul A.
Program P5_21; Uses crt; Var a:array [1..20,1..20] of real; b:array [1..20] of real; i,j,n,m:integer; p:real; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do
163
![Page 164: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/164.jpg)
Read(a[i,j]); Writeln; For j:=1 To m Do Begin p:=1; For i:=1 To n Do p:=p*a[i,j]; b[j]:=p; Writeln(b[j] :4:2); End; Readkey; Readln; End.
PROBLEMA 155.5.22Se considera tabloul X[1..n,1..m] de numere reale,unde n,m<=20. Sa se scrie un program care creaza un tablou Y[1..n] din elementele maxime de pe linii din tabloul X.
Program P5_22; Uses crt; Var x:array [1..20,1..20] of integer; y:array [1..20] of integer; i,j,n,m,max:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:');
164
![Page 165: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/165.jpg)
For i:=1 To n Do For j:=1 To m Do Read(x[i,j]); Writeln; For i:=1 To n Do Begin max:=x[i,1]; For j:=1 To m Do If x[i,j]>max Then max:=x[i,j]; y[i]:=max; Writeln(y[i] :4); End; Readkey; Readln; End.
PROBLEMA 156.5.23Se considera tabloul A[1..n,1..m] de numere reale,unde n,m<=20. Sa se scrie un program conform caruia la fiecare element al liniei i se adauga elementul A[i,i] al tabloul initial.
Program P5_23; Uses crt; Var a,b:array [1..20,1..20] of integer; i,j,n,m,s:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m);
165
![Page 166: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/166.jpg)
Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For j:=1 To m Do Begin For i:=1 To n Do Begin s:=0; s:=s+a[i,j]+a[i,i]; b[j,i]:=s; Writeln('b[',j,',',i,']=',b[j,i] :4); End; End; Readkey; Readln; End.
PROBLEMA 157.5.24Se considera tabloul A[1..n,1..m] de numere intregi si un numar intreg X,unde n,m<=20. Sa se scrie un program care determina daca in tabloul A exista elemente egale cu X.
Program P5_24; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,x:integer; Begin Clrscr; Writeln('Introdu numarul x:'); Readln(x);
166
![Page 167: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/167.jpg)
Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For i:=1 To n Do For j:=1 To m Do If a[i,j]=x Then Write('a[',i,',',j,']=',a[i,j], ' ') Else Writeln('Nu'); Readkey; Readln; End.
PROBLEMA 158.5.25Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care efectuiaza interschimbarea liniilor n1 si n2.Numerele n1(n1<n) si n2(n2<n) se intro-duc de la tastatura.
Program P5_25; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,aux,n1,n2:integer; Begin
167
![Page 168: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/168.jpg)
Clrscr; Writeln('Introdu liniile n1,n2:'); Readln(n1,n2); Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); For j:=1 To m Do Begin aux:=a[n1,j]; a[n1,j]:=a[n2,j]; a[n2,j]:=aux; End; Writeln('Tabloul dupa schimbarea lini- ilor n1 si', n2); For i:=1 To n Do Begin For j:=1 To m Do Write(a[i,j]:4); Writeln; End; Readln; End.PROBLEMA 159.5.26Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care calculeaza suma elementelor de pe fieca-re coloana.
Program P5_26; Uses crt; Var a:array [1..20,1..20] of integer; i,j,n,m,s:integer;
168
![Page 169: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/169.jpg)
Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For j:=1 To m Do Begin s:=0; For i:=1 To n Do s:=s+a[i,j]; Writeln(s:4); End; Readkey; Readln; End.
PROBLEMA 160.5.27Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20.Sa se scrie un program care determina elementul maxim si elementul minim pentru fiecare linie.
Program P5_27; Uses crt;
169
![Page 170: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/170.jpg)
Var a:array [1..20,1..20] of integer; i,j,n,max,min:integer; media1,media2:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introdu un tablou cu ',n,', linii si ',n,'coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For j:=1 To n Do Begin min:=a[1,j]; For i:=1 To n Do If a[i,j]<min Then min:=a[i,j]; Writeln('Minimul elementelor de pe linia ',j,'este:' ,min:4); End; For j:=1 To n Do Begin max:=a[1,j]; For i:=1 To n Do If a[i,j]>max Then max:=a[i,j]; Writeln('Maximul elementelor de pe linia ',j,'este:' ,min:4); End; Readln; End.PROBLEMA 161.5.28Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care creaza tabloul B[1..n,1..m],calculind fiecar element dupa formula: B[i,j]:=A[i,j] *A[i,j].
170
![Page 171: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/171.jpg)
Program P5_28; Uses crt; Var a,b:array [1..20,1..20] of integer; i,j,n,m,k,l:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln; For i:=1 To n Do Begin For j:=1 To m Do Begin b[i,j]:=a[i,j]*a[i,j]; Writeln('b[',i,',',j,']=',b[i,j]); End; End; Readkey; Readln; End.
PROBLEMA 162.5.29Se considera tabloul A[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program
171
![Page 172: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/172.jpg)
care calculeaza suma elementelor de pe «peri-metrul» tabloului si suma celorlalte elemen-te.
Program P5_29; Uses crt; Var a,b:array [1..20,1..20] of integer; i,j,n,m,s,s1,s2,s3,s4,s5,p:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introdu un tablou cu ',n,', linii si ',m,'coloane:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); s1:=0; s2:=0; s3:=0; s4:=0; s5:=0; For i:=1 To n Do For j:=1 To m Do s1:=s1+a[i,j]; For i:=1 To n Do s2:=s2+a[i,1]; For j:=2 To n-1 Do s3:=s3+a[1,j]; For i:=1 To n Do s4:=s4+a[i,n]; For j:=2 To n-1 Do s5:=s5+a[n,j]; p:=s2+s3+s4+s5; Writeln('p=',p); s:=s1-p; Writeln('s=',s); Readln; End.
172
![Page 173: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/173.jpg)
PROBLEMA 163.5.30Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20.Sa se scrie un program care determina numarul liniei cu cea mai maresuma (prima linie cu aceasta proprietate).
Program P5_30; Uses crt; Var a:array[1..20,1..20] of integer; b:array[1..20] of integer; i,j,n,k,s,max:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For i:=1 To n Do Begin s:=0; For j:=1 To n Do s:=s+a[i,j]; b[i]:=s; Write(b[i]:4); End; Writeln; max:=b[1]; For i:=1 To n Do If b[i]>=max Then k:=i; Writeln('k=',k); Readkey; Readln;
173
![Page 174: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/174.jpg)
End.
PROBLEMA 164.5.31Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20. Sa se scrie un program care determina numarul liniei cu cele mai multe elemente pozitive (prima linie cu acea-sta proprietate).
Program P5_31; Uses crt; Var a:array[1..20,1..20] of integer; b:array[1..20] of integer; i,j,n,m,k,s,max:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For i:=1 To n Do Begin s:=0;k:=0; For j:=1 To n Do If a[i,j]>0 Then k:=k+1; b[i]:=k; Write(b[i]:4); End; Writeln; k:=b[1]; For i:=1 To n Do If b[i]>=k Then s:=i;
174
![Page 175: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/175.jpg)
Writeln('k=',k); Readkey; Readln; End.PROBLEMA 165.5.32Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20.Sa se scrie un program care determina numarul coloanei cu cel mai mic produs al elementelor (prima linie cu aceasta proprietate).
Program P5_32; Uses crt; Var a:array[1..20,1..20] of integer; b:array[1..20] of integer; i,j,n,k,p,mic:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For j:=1 To n Do Begin p:=1; For i:=1 To n Do p:=p*a[i,j]; b[j]:=p; Write(b[j]:4); End; Writeln; mic:=b[1];
175
![Page 176: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/176.jpg)
For j:=1 To n Do If b[j]<=mic Then k:=j; Writeln('k=',k); Readkey; Readln; End.PROBLEMA 166.5.33Se considera doua tablouri A[1..n,1..m] si B[1..n,1..m] de numere intregi,unde n,m<=20. Sa se scrie un program care verifica daca fi-ecare element din A are aceiasi valoare ca si elementul de pe locul corespunzator din B.
Program P5_33; Uses crt; Var a:array[1..20,1..20] of integer; b:array[1..20,1..20] of integer; i,j,n,m,k,p,mic:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introduceti un tablou cu ',n,' linii si ',m,' coloane:'); Writeln('Introdu tabloul a:'); For i:=1 To n Do For j:=1 To m Do Read(a[i,j]); Writeln('Introdu tabloul b:'); For i:=1 To n Do For j:=1 To m Do Read(b[i,j]); i:=0; j:=0; Repeat
176
![Page 177: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/177.jpg)
i:=i+1; j:=j+1; Until (i=n) and (j=n) or (a[i,j]<>b[i,j]); Write('Rezultatul:'); If a[i,j]=abs(b[i,j]) Then Writeln('Tablourile sunt identice') Else Writeln('Tablourile nu sunt identice'); End.PROBLEMA 167.5.34Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20.Sa se scrie un program ca-re determina elementul maxim pentru fiecarelinie si calculeaza suma lor;elementul maxim pentru fiecare coloana si suma lor.
Program P5_34; Uses crt; Var a:array[1..20,1..20] of integer; b:array[1..20] of integer; i,j,n,max1,max2,s:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' li- nii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For j:=1 To n Do Begin max1:=a[1,j]; s:=0; For i:=1 To n Do Begin If a[i,j]>max1 Then
177
![Page 178: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/178.jpg)
max1:=a[i,j]; s:=s+a[i,j]; End; Writeln('Maximul de pe coloana ',j,' este',' ', max1); Writeln('Suma pe coloana ',j,' este',' ', s); End; For i:=1 To n Do Begin max2:=a[i,1]; s:=0; For j:=1 To n Do Begin If a[i,j]>max2 Then max2:=a[i,j]; s:=s+a[i,j]; End; Writeln('Maximul de pe linia ',i,' ste',' ', max2); Writeln('Suma de pe linia ',i,' este',' ', s); End; Readkey; Readln; End.
178
![Page 179: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/179.jpg)
PROBLEMA 168.5.35Se considera tabloul A[1..n,1..n] de numere intregi si un numar C,unde n<=20.Sa se scrie un program care afiseaza toate pozitiile in care apare acest element.
Program P5_35; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,c:integer; Begin Clrscr; Writeln('Introdu c:'); Readln(c); Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); For i:=1 To n Do
179
![Page 180: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/180.jpg)
Begin For j:=1 To n Do If a[i,j]=c Then Writeln('i=',i,' ','j=',j); End; Readkey; Readln; End.
PROBLEMA 169.5.36Se considera tabloul A[1..n,1..m] de numere intregi si un numar k(1<=k<=n),unde n,m<=20. Sa se scrie un program care exclude a coloa-nei cu numarul k.
Program P5_36; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,m,k:integer; Begin Clrscr; Writeln('Introdu coloana k:'); Readln(k); Writeln('Intodu numarul componentelor n,m:'); Readln(n,m); Writeln('Introduceti un tablou cu ',n,' linii si ',m,' coloane:'); For i:=1 To n Do
180
![Page 181: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/181.jpg)
For j:=1 To m Do Read(a[i,j]); If (k<1) or (k>n) Then Begin Write('Nu exista asa coloana'); Exit; End; For j:=k To m-1 Do For i:=1 To n Do a[i,j]:=a[i,j+1]; Dec(m);Writeln('Tabloul fara coloana a ',k,'este:');For i:=1 To n Do BeginFor j:=1 To m Do Write(a[i,j]:4); Writeln; End; Readln; End.PROBLEMA 170.5.37Se considera tabloul A[1..n,1..m] de numere intregi si un numar k(1<=k<=n),unde n,m<=20. Sa se scrie un program care exclude linia si coloana la intersectia carora se afla ele-mrntul maxim de pe diagonala principala.
Program P5_37; Uses crt; Var a:array[1..20,1..20] of integer; i,j,n,m,max,q,w:integer; Begin Clrscr; Writeln('Intodu numarul componentelor n:'); Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do
181
![Page 182: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/182.jpg)
For j:=1 To n Do Read(a[i,j]); max:=a[1,1]; For i:=1 To n Do If a[i,i]>max Then Begin max:=a[i,i]; q:=i; End; For i:=q To n-1 Do For j:=1 To n Do a[i,j]:=a[i+1,j]; Dec(n); Writeln('Tabloul fara coloana a ',q,' si linia ',q,' este:'); For i:=1 To n Do Begin For j:=1 To n Do Write(a[i,j]:4); Writeln; End; Readln; End.PROBLEMA 171.5.38Se considera tabloul A[1..n,1..n] de numere intregi,unde n<=20.Sa se scrie un program ca-re determina daca acest tablou este un patrat magic,adica sumele elementelor de pe linii ,coloane si diagonale sunt egalea.
Program P5_38; Uses crt; Label nu,sf; Var a:array[1..20,1..20] of integer; i,j,n:integer; dp,ds,so,sv:real; Begin Clrscr; Writeln('Intodu numarul componentelor n:');
182
![Page 183: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/183.jpg)
Readln(n); Writeln('Introduceti un tablou cu ',n,' linii si ',n,' coloane:'); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); dp:=0; ds:=0; so:=0; sv:=0; For i:=1 To n Do Begin dp:=dp+a[i,j]; ds:=ds+a[i,n+1-i]; If dp<>ds Then goto nu; For j:=1 To n Do Begin so:=so+a[i,j]; sv:=sv+a[i,j]; End; If (so<>dp) or (sv<>ds) Then goto nu Else Writeln('Patrat magic'); goto sf; nu:Writeln('Nu-i patrat magic' ); sf:readkey; End; End.PROBLEMA 172.5.39Se considera tabloul A[1..n,1..n] de numere intregi, unde n<=20.Sa se scrie un program care determina elementul maxim de pe fiecaresector, care se obtine la impartirea lui in patru tablouri.De exemplu 2 5 3 6 in 2 5 3 6 4 8 0 1 4 9 0 7 4 9, 0 7, 7 9, 2 4. 0 1 4 8 2 4 7 9 Program P5_39; Uses Crt; Var a:array[1..20,1..20] of integer; i,j,n,max1,max2,max3,max4:integer;
183
![Page 184: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/184.jpg)
Begin Clrscr; Write('Introdu n:'); Readln(n); For i:=1 To n Do For j:=1 To n Do Read(a[i,j]); max1:=a[1,1]; For i:=1 To n div 2 Do for j:=1 To n div 2 Do If a[i,j]>max1 Then max1:=a[i,j]; Writeln('max1=',max1); max2:=a[1,n]; For i:=n Downto n div 2+1 Do for j:=1 To n div 2+1 Do If a[i,j]>max2 Then max2:=a[i,j]; Writeln('max2=',max2); max3:=a[n,n]; For i:=n Downto n div 2+1 Do for j:=n Downto n div 2+1 Do If a[i,j]>max3 Then max3:=a[i,j]; Writeln('max3=',max3); max4:=a[1,n]; For j:=n div 2+1 To n Do for i:=1 To n div 2 Do If a[i,j]>max4 Then max4:=a[i,j]; Writeln('max4=',max4); Readkey; Readln; End.
Programe cu siruri de caractere
PROBLEMA 173.6.1Sa se scrie un program care citeste un sir de caractere si afiseaza lungimea lui.
Program P6_1; Uses Crt; Var s:string; p:integer; Begin Clrscr;
184
![Page 185: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/185.jpg)
Writeln('Introdu un sir de caractere:'); Readln(s); Write('A fost introdus sirul:'); Writeln(s); p:=Length(s); Writeln('Sirul s contine', p,',caractere'); Readkey; Readln; End.
PROBLEMA 174.6.2Se considera un sir de caractere.Sa se scrie un program care calculeaza numarul sumar de aparitii ale caracterelor "a" si "b".
Program P6_2; Uses Crt; Var s,a,b:string; i,k,l,total:integer; Begin Clrscr;
185
![Page 186: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/186.jpg)
Writeln('Introdu un sir de caractere:'); Readln(s); Write('Introdu caracterul a:'); Readln(a); k:=0; For i:=1 To Length(s) Do If s[i]=a Then k:=k+1; Writeln('k=',k); Write('Introdu caracterul b:'); Readln(b); l:=0; For i:=1 To Length(s) Do If s[i]=b Then l:=l+1; Writeln('l=',l); total:=k+l; Writeln('total=',total); Readkey; Readln; End.
PROBLEMA 175.6.3Se considera un cuvint, care consta din lite-re mici ale alfabetului latin.Sa se scrie un program care:a) numara aparitia silabei "re";b) inlocuieste secventa "do" cu "re".
Program P6_3; Uses Crt;
186
![Page 187: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/187.jpg)
Var s:string; i,k:integer; Begin Clrscr; Writeln('Introdu un sir de caractere:'); Readln(s); k:=0; For i:=1 To Length(s) Do If (s[i]='r') and (s[i+1]='e') Then k:=k+1; Writeln('In sir se intilnesc ',k,' silabe de "re" '); For i:=1 To Length(s) Do If (s[i]='d') and (s[i+1]='o') Then Begin s[i]:='r'; s[i+1]:='e'; End; Write('Sirul obtinut este: ',s); Readkey; Readln; End.
PROBLEMA 176.6.4Sa se scrie un program care afiseaz "DA" sau "NU", in dependenta de faptul daca o litera arbitrara x se contine sau nu in cuvintul dat y.
Program P6_4;
187
![Page 188: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/188.jpg)
Uses Crt; Var s:string; i,k:integer; Begin Clrscr; Writeln('Introdu un cuvint:'); Readln(s); For i:=1 To Length(s) Do If s[i]='x' Then k:=i; if k<>0 then Writeln('DA') Else Writeln('NU'); Readkey; Readln; End.
PROBLEMA 177.6.5Se considera cuvintul X. Sa se scrie un pro-gram care afiseaza caracterele acestui cuvint in ordine inversa.
188
![Page 189: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/189.jpg)
Program P6_5; Uses Crt; Var x,y:string; i:integer; Begin Clrscr; Writeln('Introdu un cuvint:'); Readln(x); y:=''; For i:=1 To Length(x) Do y:=x[i]+y; Writeln('Cuvintul inversat:',y); Readkey; Readln; End.
PROBLEMA 178.6.6
189
![Page 190: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/190.jpg)
Se considera o propozitie formata din cuvinte separate prin spatiu. Propozitia se termina cu punct .Sa se scrie un program care numara cite cuvinte are propozitia.
Program P6_6; Uses Crt; Var s:string; i,k:integer; Begin Clrscr; Writeln('Introdu o propozitie:'); Readln(s); k:=0; For i:=1 To Length(s) Do If s[i]=' ' Then k:=k+1; Writeln('Propozitia are ',k,' cuvinte'); Readkey; Readln; End.
190
![Page 191: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/191.jpg)
PROBLEMA 179.6.7Se citeste un numar din cinci cifre.Sa se scrie un program care afiseaza numarul format dupa eliminarea cifrei din mijloc.
Program P6_7; Uses Crt; Var s:string; Begin Clrscr; Writeln('Introdu un numar din cinci cifre:'); Readln(s); Delete(s,3,1); Writeln('Numarul dupa stergerea cifrei din mijloc este ',s); Readkey; Readln; End.
191
![Page 192: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/192.jpg)
PROBLEMA 180.6.8Se considera un sir format din cel mult 80 de caractere.Sa se scrie un program care inlocu-ieste o litera data prin alta litera data in tot sirul.
Program P6_8; Uses Crt; Var s,x,y:string; i:integer; Begin Clrscr; Writeln('Introdu un sir de caractere:'); Readln(s); Writeln('Introdu un caracter :'); Readln(x); Writeln('Introdu caracterul nou:'); Readln(y); For i:=1 To Length(s) Do If Copy(s,i,1)=x Then Begin Delete(s,i,1); Insert(y,s,i); End; Writeln('Sirul dupa mudificare este:'); Writeln(s); Readkey; Readln; End.
192
![Page 193: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/193.jpg)
PROBLEMA 181.6.9Se considera cuvintul X.Sa se scrie un pro-gram care verifica daca cuvintul dat contine mai multe vocale decit consoane.
Program P6_9; Uses crt; Var x:string; i:byte; k,l:integer; Begin Clrscr; Write('Introdu un cuvint:'); Readln(x); k:=0; l:=0; For i:=1 To Length(x) Do If (x[i]='a') or (x[i]='o') or (x[i]='u') or (x[i]='i') or (x[i]='e') Then Inc(k) Else Inc(l); If k>l Then Writeln('Acest cuvint contine mai multe vocale') Else Writeln('Acest cuvint contine mai multe consoane'); Readln; Readkey; End.
193
![Page 194: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/194.jpg)
Programe cu articole(record)
Problema 182.7.1Sa se scrie un program ce citestee te la tas-tatura datale referitoare la n elevi si afi-seaza pe ecran numele, prenumele si nota me-die a celui mai bun elev. Se considera ca elevii au note medii diferite.
Program P7_1; Type Elev=Record Nume:string;Prenume:string; NotaMedie:real;End; ListaElev=Array[1..40] of Elev; Var E :Elev; LE:ListaElev; n :1..40; i :integer; Begin Write('n='); Readln(n); For i:=1 To n Do Begin Writeln('Dati datele elevului ',i); Write('Numele: ');Readln(LE[i].Nume); Write('Prenumele: '); Readln(LE[i].Prenume); Write('Nota medie: '); Readln(LE[i].NotaMedie); End; E.NotaMedie:=0;
194
![Page 195: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/195.jpg)
For i:=1 To n Do If LE[i].NotaMedie>E.NotaMedie Then E:=LE[i]; Writeln('Cel mai bun elev este: '); Writeln(E.Nume,' ',E.Prenume,E.NotaMedie :5:2); Readln; End.Problema 183.7.2Se considera numarul a N persoane si cistigul lor pentru o luna.Sa se scrie un program care calculeaza salariul fiecarei persoane fara impozite.Impozitele se calculeaza dupa cum urmeaza: 0 -100lei -0% 100.1-399.99lei -13% 400 -599.99lei -25% 600 -si mai mult-30% .
Program P7_2; Uses crt; Type Persoana=Record Nume:string;Cistig,Salariu:real; End; Var x:Array[1..30] of Persoana; i :integer; imp:Real;n:1..100; Begin Clrscr; Write('Introdu numarul de peersoane: '); Readln(n);For i:=1 To n Do Begin Writeln('Introdu datele persoanei ',i); Write('Numele: ');Readln(Nume); Write('Cistigul: ');Readln(Cistig); End; For i:=1 To n Do Begin If x[i].Cistig<=100 Then imp:=0 Else If (x[i].Cistig>100) And (x[i].Cistig <400)Then imp:=0.13*x[i].Cistig Else If (x[i].Cistig>=400)And
195
![Page 196: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/196.jpg)
x[i].Cistig<600) Then imp:=0.25*x[i].Cistig Else imp:=0.3*x[i].Cistig; x[i].Salariu:=x[i].Cistig-imp; End;Writeln('Lista persoanelor si salariile fara impozite: '); For i:=1 To n Do Writeln(x[i].Nume,' ',x[i].Salariu:5:2); Readln; Readkey; End.Problema 184.7.3Se considera o lista cu oferte de vinzare a locuintelor ce contine urmatoarele date:-numarul ofertei(1..100); -sector(string); -numarul de odai(1..5); -pretul(real); -telefon("da"sau"nu").Sa se scrie un program care ar afisa sectoa-rele unde sunt de vinzare locuinte 4 odai ce au telefon si prretul mediu al acestora.
Program P3; Uses crt; Type Oferta=Record Nr:1..100; Sector:string; No:1..5;Pret:real; Tel:String[2];End; Var A:Array[1..50] of Oferta;i,n,l :integer; PretMediu,s:Real; Begin Clrscr; Write('Introdu numarul de oferte: '); Readln(n);For i:=1 To n Do With A[i] Do Begin Write('Numarul ofertei '); Redln(Nr); Write('Sectorulumele: ');Readln(Nume); Write('Cistigul: ');Readln(Cistig); End;
196
![Page 197: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/197.jpg)
For i:=1 To n Do Begin If x[i].Cistig<=100 Then imp:=0 Else If (x[i].Cistig>100) And (x[i].Cistig<400)Then imp:=0.13*x[i].Cistig Else If (x[i].Cistig>=400)And (x[i].Cistig<600) Then imp:=0.25*x[i].Cistig Else imp:=0.3*x[i].Cistig; x[i].Salariu:=x[i].Cistig-imp;End; Writeln('Lista persoanelor si salariile fara impozite: '); For i:=1 To n Do Writeln(x[i].Nume,' ',x[i].Salariu:5:2); Readln; Readkey; End.
Programe cu fisiere
Problema 185.8.1Sa se scrie un program care creaza un fisier text.Continutul liniilor se introduc de la tastatura.
Program P8_1; var f:text; c:string; i:1..100; n:integer; Begin Assign(f,'Fisier1.txt'); Rewrite(f); Write('Dati numarul de linii:'); Readln(n); For i:=1 To n Do Begin Readln(c); Writeln(f,c); End; Close(f);
197
![Page 198: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/198.jpg)
Readln; End.
Problema 186.8.2Sa se scrie un program care citeste de la tastatura cite trei numere reale a,b,c pe care le scrie in fisierul IN.TXT.Apoi citind aceste trei numere, reprezentind laturile unui triunghi, scrie in fisierul OUT.TXT numerele a,b si c,semiperimetrul p si aria triunghiului s.
Program P8_2; var f,g:text; a,b,c,p,s:real; str:string; Begin Assign(f,'IN.TXT'); Rewrite(f); Write('Dati numerele reale a,b,c :'); While not eof Do Begin Readln(a,b,c); Writeln(f,a:8:2, b:8:2, c:8:2); End; Close (f); Reset (f); Assign(g,'OUT.TXT');Rewrite(g); While not eof(f) Do Begin Readln(f, a, b, c); Write(g, a:8:2, b:8:2, c:8:2);
198
![Page 199: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/199.jpg)
p:=(a+b+c)/2; s:=sqrt(p*(p-a)*(p-b)*(p-c)); Writeln(g, p:15:2, s:15:2); End; Close (f); Close (g); Reset (g); While not eof(g) Do Begin Readln(g,str); Writeln(str); End; Close (g); Readln; End. For i:=1 To n Do Begin Readln(c); Writeln(f,c); End; Close(f); Readln; End.Problema 187.8.3Intr-un fisier este inscris o poezie. Sa se scrie un program care creeaza un alt fisier cu acelasi continut, in care toate literelesa fie majuscule.
Program P8_3; var f1,f2:text; s,k:string; i:integer; Begin Write('Dati numele fisierului:'); Readln(s); Assign(f1,s); Reset(f1); Assign(f2,'LitMari.txt'); Rewrite(f2); While not eof(f1) Do Begin Readln(f1,k);
199
![Page 200: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/200.jpg)
For i:=1 To Length(k) Do k[i]:=Upcase(k[i]); Writeln(f2,k); End; Close(f1); Close(f2); Reset(f2); While not eof(f2) Do Begin Readln(f2,k); Writeln(k); End; Close(f2); Readln; End.
Programe cu multimi
PROBLEMA 188.9.1Sa se scrie un program care introduce de la tastatura doua multimi de numere pozitive din doua cifre si afiseaza reuniunea acestor mul-timi.
Program P9_1; Uses crt; Var i,n,a:0..99; s,r,m:set of byte; Begin Clrscr; Writeln('Cite numere va avea prina multime n='); Readln(n); m:=[]; For i:=1 To n Do
200
![Page 201: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/201.jpg)
Begin Readln(a); m:=m+[a]; End; Write('Cite numere va avea multimea a doua n='); Readln(n); r:=[]; For i:=1 To n Do Begin Readln(a); r:=r+[a]; End; s:=m+r; Write('Reuniunea multimilor m si r este:'); For i:=1 To 99 Do If i In s Then Write(i,' '); Readln; End.
PROBLEMA 189.9.2Sa se scrie un program care introduce de la tastatura doua multimi de numere pozitive din doua cifre si afiseaza intersectia si iferen-ta acestor multimi.
Program P9_2; Uses crt; Var k,i,n:0..99;odat,mult:set of byte; Begin Clrscr; odarWriteln('Cite numere va avea prina multime n='); Readln(n); m:=[]; For i:=1 To n Do Begin
201
![Page 202: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/202.jpg)
Readln(a); m:=m+[a]; End; Write('Cite numere va avea multi- mea a doua n='); Readln(n); r:=[]; For i:=1 To n Do Begin Readln(a); r:=r+[a]; End; s:=m*r; Write('Intersestia multimilor m si r este:'); For i:=1 To 99 Do If i In s Then Write(i,' '); Writeln; s:=m-r; Write('Diferenta multimilor m si r este:'); For i:=1 To 99 Do If i In s Then Write(i,' '); Readln; End.PROBLEMA 190.9.3Sa se scrie un program care calculeaza nume-rele prime mai mici decit un numar natural; folosind algoritmul Ciurul (sita) lui Eratos-tene.
Program P9_3; const n=50; Type MultimeDeNumere=set of 1..n; Var Sita,NumerePrime:MultimeDeNumere; i,m:integer; Begin Sita:=[2..n]; NumerePrime:=[];
202
![Page 203: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/203.jpg)
i:=2; Repeat While not (i in Sita) Do i:=succ(i); NumerePrime:=NumerePrime+[i]; Write(i:4); m:=i; While m<=n Do Begin Sita:=Sita-[m]; m:=m+i; End; Until Sita=[]; Writeln; Readln; End.
PROBLEMA 191.9.4Se considera cuvintul X format din litere ma-juscule ale alfabetului latin. Sa se un pro-gram care deternina literele ce apar o sin-gura data si literele care apar de mai multe ori in cuvintul dat.
Program P9_4; Uses crt; Var x:string; odat,mult:set of char; j:char;
203
![Page 204: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/204.jpg)
i:integer; Begin Clrscr; Write('Introdu cuvintul :'); Readln(x); odat:=[]; mult:=[]; For i:=1 To Length(x) Do If x[i] In odat Then mult:=mult+[x[i]] Else odat:=odat+[x[i]]; odat:=odat-mult; Write('Literele ce apar o singura data :'); For j:='A' To 'Z' Do If j In odat Then Write(j,' '); Writeln; Write('Literele ce apar de mai multe ori:'); For j:='A' To 'Z' Do If j In mult Then Write(j,' '); Readln; End.
PROBLEMA 192.9.5De la tastatura se introduc numere intregi pozitive din doua cifre.Introducerea va lua sfirsit la tastarea numarului zero.Sa se un program careextrage in ordine crescinda nu-merele ce apar in sirul de intrare doar o singura data si numarul acestora.
Program P9_5; Uses crt;
204
![Page 205: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/205.jpg)
Var odat,mult:set of byte; i,n:1..99;k:integer; Begin Clrscr; odat:=[]; mult:=[]; Readln(n); While n<>0 Do Begin If n In odat Then mult:=mult+[n] Else odat:=odat+[n]; Readln(n); End; odat:=odat-mult; k:=0; For i:=10 To 99 Do If i In odat Then k:=k+1; Write('O singura data in sirul de intrare apar',k,'numere:['); For i:=10 To 99 Do If i In odat Then Write(i,' '); Write(']'); Readln; End.
Subprograme
PROBLEMA 193.10.1Se considera trei numere intregi a,b,c.Sa se scrie un program care aranjeaza aceste numere in ordinea crescatoare.
Program P10_1;
205
![Page 206: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/206.jpg)
Uses crt; Var a,b,c:integer; Procedure Schimba(Var x,y:integer); Var aux:integer; Begin aux:=x; x:=y; y:=aux; End; Begin Clrscr; Writeln('Introdu trei numere intregi:'); Readln(a,b,c); If a>b Then Schimba(a,b); If b>c Then Schimba(b,c); If a>b Then Schimba(a,b); Write('Numerele aranjate crescator:',a,' ',b,' ',c); Readln; End.
PROBLEMA 194.10.2Se considera tabloul A[1..n] de numere intregi ,n<=100.Sa se scrie un program care calculeaza suma componentelor acestui ta-blou,utilizind functia respectiva .
Program P10_2;
206
![Page 207: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/207.jpg)
Uses crt; Type tablou=array[1..100] of integer; Var a:tablou; s,n:integer; Procedure Citire; Var i:integer; Begin For i:=1 To n Do Read(a[i]); End; Function Suma (n:integer;a:tablou):integer; Var i,s:integer; Begin s:=0; For i:=1 To n Do s:=s+a[i]; Suma:=s; End; Begin Clrscr; Write('Introdu componentul tabloului :'); Readln(n); Write('Introdu ',n,' elementele :'); Citire; Write('Suma elementelor este: ',Suma(n,a) ); Readln; End.
PROBLEMA 195.10.3Se considera un patrulater convex cu lun-gimile celor patru laturi si una din dia-gonale.Sa se calculeze aria acestui patru-later.
207
![Page 208: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/208.jpg)
Program P10_3; Uses crt; Var AB,BC,CD,AD,AC,S1,S2:real; Procedure Aria(a,b,c:real; Var s:real); Var p:real; Begin P:=(a+b+c)/2; s:=sqrt(p*(p-a)*(p-b)*(p-c)); End; Begin Clrscr; Writeln('Dati lungimile laturilor si a diagonalei:'); Readln(AB,BC,CD,AD,AC); Aria(AB,BC,AC,S1); Aria(AD,CD,AC,S2); Write('Raspuns: aria patrulaterului convex este ',S1+S2:5:3); Readln; End.
PROBLEMA 196.10.4
208
![Page 209: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/209.jpg)
Se considera trei numere intregi a,b,c.Sa se scrie un program care aranjeaza aceste numere in ordinea crescatoare.
Program P10_4; Uses crt; Var i,n,m,l:integer; Function Prim(k:integer):Boolean; Var i:integer; r:Boolean; Begin r:=True; i:=2; l:=Trunc(k/2); While(i<=l) And r Do Begin If k Mod i=0 Then r:=False; i:=i+1 End; Prim:=rEnd; Begin Clrscr; Writeln('Introdu doua numere m si n (m<n):'); Readln(m,n); Write('Numarele prime din intervalul', m,'.. ',n,'sunt:'); For i:=m To n Do If Prim(i) Then Write(i,' '); Readln; End.
209
![Page 210: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/210.jpg)
PROBLEMA 197.10.5Se alcatuit un program care calculeaza facto-rialul.
Program P10_5; Uses crt; Function Factorial(n : integer):integer; Var p,i:integer; Begin Write('Introdu n='); Readln(n); p:=1; For i:=1 To n Do p:=p*i; Factorial:=p; End; Begin Clrscr; Writeln(Factorial(4)); Readln; Readkey; End.
210
![Page 211: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/211.jpg)
PROBLEMA 198.10.6Se considera tabloul A[1..n] de numere in-tregi pozitive formate din cel mult patru cifre,n<=100. Sa se calculeze suma numerelorinversate din tablou, utilizind functia, care inverseaza un numar intreg.
Program P10_6; Const nmax=100; Type tablou=array[1..nmax] of integer; Var a:tablou; i,s,k:integer; m:1..nmax; Function Invers(n:integer):integer; Var NumInv :integer; Begin NumInv:=0; While n<>0 Do Begin k:=n mod 10; NumInv:=NumInv*10+k; n:=n div 10; End; Invers:=NumInv; End; Begin Writeln('Introdu numarul de componente m='); Readln(m); Write('Dati ', m,' numere naturale:'); For i:=1 To m Do Read(a[i]);
211
![Page 212: 203.2006](https://reader036.vdocuments.mx/reader036/viewer/2022062513/5571f95d49795991698f687c/html5/thumbnails/212.jpg)
s:=0; For i:=1 To m Do s:=s+Invers(a[i]); Writeln('Suma numerelor inversate este : ,s); Readln; End.
212