Лаб 3 Сортування литтям program gena; {zluttja} const n=8; type mas=array[1..n] of integer; var x1,x2:mas; i:integer; Function riz(mas:mas):integer; var i,j,count:integer; begin count:=1; j:=2; while(j<=N) do begin {j:=i+1;} while(j<=N) and (mas[j-1]=mas[j]) do inc(j); if j>N then break; inc(count); inc(j); end; riz:=count end; procedure mrg(var y,x:mas; m,s,r:integer); var mr,k,i,j,por,obm:integer; begin mr:=m+s; i:=m; j:=mr; for k:=m to m+s+r-1 do if i>m+s-1 then begin x[k]:=y[j]; j:=j+1; end else if j>mr+r-1 then begin x[k]:=y[i]; i:=i+1; end else if y[i]>y[j] then begin x[k]:=y[i]; i:=i+1; end else begin x[k]:=y[j]; j:=j+1; end;end; procedure Mrg_rec(var a,b:mas; l,r:integer); var m,k:integer; begin if l>=r then exit; m:=(l+r) div 2; Mrg_rec(a,b,l,m); Mrg_rec(a,b,m+1,r); mrg(a,b,l,m-l+1,r-m); for k:=1 to r do a[k]:=b[k]; end; begin for i:=1 to n do read(x1[i]); mrg_rec(X1,X2,1,n); writeln; for i:=1 to n do writeln(x1[i]); readln; writeln('sortyvannja vukonano!'); writeln('kilkistj riznuh elementiv: ',riz(x1)); readln; end. Сортування вставкою #include <stdio.h> #include <conio.h> int DifferentEl(int *mas,int kst); void selection(int *array, int length); int main(void) { int mas1[10]; int n,i,j; puts("sortyvannja vuborom"); puts("vveditj kilkistj elementiv sortyvannja"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&mas1[i]); selection(mas1,n); for(i=0;i<n;i++) printf("%d ",mas1[i]); printf("\nDifferent elements %d",DifferentEl(mas1,n)); getch(); return 0; } int DifferentEl(int *mas,int kst) { int ii,jj,nn=kst; for(ii=0;ii<kst;ii++) { for(jj=ii+1;jj<kst;jj++) { if(mas[ii]==mas[jj]) {nn--; break;} } } return nn; } void selection(int *array, int length) { int max, i, temp; while(length > 0) { max = 0; for(i = 1; i < length; i++) if (array[i] > array[max]) max = i;
temp = array[length-1]; array[length-1] = array[max]; array[max] = temp; length--; } } Лаб 4 program talglab4; var xo,yo,xa,ya,xb,yb : integer ; a,b,c,s,hor,rez,rezult,l,kyt: real; p,z,grad:double; r:byte; beta:single; function ArcSin ( s : double ): double; begin if s = 1.0 then { to avoid division by 0 } ArcSin := Pi / 2.0 else ArcSin := ArcTan ( s / Sqrt ( 1 - s * s ) ); end; begin writeln('vveditj koordunatu centra kola xo'); readln(xo,yo); writeln('vveditj koordunatu prjamoji'); readln(xa,ya,xb,yb); writeln('vveditj radius kola'); readln(r); a:=sqrt(sqr(xb-xo)+sqr(yb-yo)); {znahod*y vidstanj mi* to4kamu} b:=sqrt(sqr(xa-xo)+sqr(ya-yo)); c:=sqrt(sqr(xb-xa)+sqr(yb-ya)); writeln('Dov*unu storin trukytnuka',a:10:3,' ',b:10:3,' ',c:10:3); p:=a*(sqrt(1-(sqr((b*b-a*a-c*c)/(-2*a*c))))); writeln('dov*una perpendukyljara',p:10:3); if p<=r then writeln('prjama le*utj na koli') else writeln('prjama i kolo ne peretunajutsja'); s:=p/r; hor:=(r*r-2*r*p+p*p)*2; readln; rez:=ArcSin(s); rezult:=rez*57.29; kyt:=(180-90-rezult)*2; writeln('kyt rivnuj',kyt:10:3); writeln('p', p:10:3); writeln('radius kola', r); writeln('rez:',rez:10:3); l:=(2*3.14*r*kyt)/360; writeln('dov*una hordu', l:5:3); readln; end. Лаба 5 #include <stdio.h> #include <conio.h> #define N 5 // Kilkist chysel int main (void) { int arr[N]={NULL}; //masyv vvedenyh chysel int i,j; int ch=0; //chyslo shcho shukaemo int per=1; //kilkist perevirok clrscr(); printf("VVedit %d elementiv masyvu\n",N); for (i=0;i<N;i++) { scanf("%d",&arr[i]); } printf("Robymo poshuk doky vvodiat`sia chysla\n"); printf("Shcho shukaemo?\n"); while (scanf("%d",&ch)) { for (i=0; i<N; i++) if (ch==arr[i]) { printf("Znajdeno za %d ",per); if (per%10==1) printf("perevirku\n"); else if ((per%10>1) && (per%10<5)) printf("perevirky\n"); else if ((per%10>=5) || (per%10==0)) printf("perevirok\n"); printf("Shcho dali shukaemo?\n"); per=1; if (i>0) { ch=arr[0]; arr[0]=arr[i]; arr[i]=arr[i-1]; for(j=i-1; j>0; j--) { arr[j+1]=arr[j]; } arr[1]=ch; } break; } else per++; } return 0; } Лаба 2 uses crt; var b : string; d2,d1,d3,d4,d5:word; a,pc,ost:word; s:string; function DEC_BIN(x:word):string; const digits:array [0..1] of char = ('0','1'); var res:string; d:0..1; begin res:=''; while (x<>0) do begin d:=x mod 2; res:=digits[d]+res; x:=x div 2; end; DEC_BIN:=res; end; begin writeln('vveditj dovge desjatkove cuslo a= '); readln( a ); writeln( DEC_BIN(a) ); d1:=a shl 1; writeln( DEC_BIN(d1) ); d2:=d1 or a; writeln( DEC_BIN(d2) ); d1:=d2 shl 2; writeln( DEC_BIN(d1) ); d2:=d1 or d2; writeln( DEC_BIN(d2) ); d1:=d2 shl 4; writeln( DEC_BIN(d1) ); d2:=d1 or d2; writeln( DEC_BIN(d2) ); d3:=d2 shl 1; writeln( DEC_BIN(d3) ); d4:=d2 and d3; writeln( DEC_BIN(d4) ); d5:=a and d4; writeln( DEC_BIN(d5) ); ost:=d5; writeln ('ost: ',ost); readln; end.