Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Черкашин Практика 1-4.doc
Скачиваний:
1
Добавлен:
25.09.2019
Размер:
849.41 Кб
Скачать

Implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

x:=1;

memo1.lines.add('Pochatkovyu massyv');

for i:=1 to n do

begin

z[i]:=abs(abs(sin(x*x/5-2))+11*cos(6*x-1));

x:=x+1;

memo1.lines.add('z['+floattostr(i)+']= '+floattostr(z[i]));

if (z[i]>max) then

max:=z[i];

end;

for i:=1 to n do

begin

if (z[i]>0) then

begin

z[i]:=max;

break;

end;

end;

memo1.Lines.add('kincevyu massyv');

for i:=1 to n do

memo1.Lines.add('z['+floattostr(i)+']= '+floattostr(z[i]));

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

close;

end;

end.

7) С/С++

#include "stdafx.h"

#include <stdio.h>

#include <cmath>

using namespace std;

int main()

{

const int k=4,n=4;

float a[k][n],s=0;

int i=0,j=0,k1=0;

for (i=1;i<=k;i++)

{for (j=1;j<=n;j++)

{

a[k][n]=j*(13*cos(abs(i+0.0)+0.0)*sin(i*i-2+0.0))+sin(i+0.0)*(abs(cos(j*j-3+0.0)+0.0)/4-9*sin(j-3+0.0));

printf("%7.2f ",a[k][n]);

if (a[k][n]>0) s+=a[k][n];

if (a[k][n]<0) k1+=1;

}

printf("\n");}

printf("\nsuma dodatnih elementiv v massyvi = %f\n\n",s);

printf("kilkist vid'emnyh elementiv v massyvi = %d\n\n",k1);

return 0;

}

7)Pascal

unit Unit1;

Interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

Button1: TButton;

Memo1: TMemo;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const k=4;n=4;

var

Form1: TForm1;

Implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

a:array[1..k,1..n]of real;

s,k1:real;

i,j:integer;

begin

for i:=1 to n do

begin

for j:=1 to k do

begin

a[k][n]:=j*(13*cos(abs(i+0.0)+0.0)*sin(i*i-2+0.0))+sin(i+0.0)*(abs(cos(j*j-3+0.0)+0.0)/4-9*sin(j-3+0.0));

stringgrid1.Cells[j-1,i-1]:=floattostrf(a[k][n],ffgeneral,5,2);

if (a[k][n]>0) then s:=s+a[k][n];

if (a[k][n]<0) then k1:=k1+1;

end;

end;

memo1.Lines.add('suma dod elementiv = '+floattostrf(s,ffgeneral,5,2));

memo1.Lines.add('kilkist vidyemnyh elementiv = '+floattostrf(k1,ffgeneral,5,2));

end;

end.