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

Int _tmain(int argc, _tchar* argv[])

{ float x,y,x0,x1,dx,k=1;

int k1=0;

printf("vvedit pochatkove znachennya: ");scanf("%f/n",&x0);

printf("vvedit kinceve znachennya: ");scanf("%f/n",&x1);

printf("vvedit krok: ");scanf("%f/n",&dx);

x=x0;

printf("|-------------|\n");

printf("| x | y |\n");

printf("|-------------|\n");

for (x=x0;x<=x1;x+=0.1*dx)

{y=cos(2*x)*sin(fabs(x))/(15-5);

printf("|%6.2f|%6.2f|\n",x,y);

if (y>3 || y<-4) {k*=y;k1+=1;}}

printf("|-------------|\n");

if (k>1 && k<1) printf ("Dobutok znachen y>3 and y<-4 : %f",k);

else printf(" shykanyh danyh ne isnye \n");

return 0;

}

5)Pascal

var

Form1: TForm1;

Implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var x,y,x0,x1,dx,k:real;

k1:integer;

begin

k:=1;

k1:=0;

x0:=strtofloat(edit1.text);

x1:=strtofloat(edit2.text);

dx:=strtofloat(edit3.text);

memo1.Lines.Add('|---------------------------------------------------------------|');

memo1.Lines.Add('| x | y |');

memo1.Lines.Add('|---------------------------------------------------------------|');

x:=x0;

while (x<=x1+0.1*dx/2) do

begin

y:=cos(2*x)*sin(abs(x))/(15-5);

memo1.Lines.add('|'+floattostrf(x,ffgeneral,6,2)+' | '+floattostrf(y,ffgeneral,6,2));

x:=x+0.1*dx;

if ((y < (-4)) or (y>3)) then

begin

k:=k*y;

k1:=k1+1;

end;

end;

if ((k1>1) and (k<1)) then

begin

memo1.Lines.add('Dobutok znachen y>3 and y<-4 : '+floattostrf(k,ffgeneral,5,2));

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

end

else memo1.Lines.add('shykanyh danyh ne isnye');

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

close;

end;

end.

6) C/C++

#include "stdafx.h"

#include "math.h"

#include <cmath>

Int _tmain(int argc, _tchar* argv[])

{ const int n=7;

float z[n+2],max=0;

int x=1,i;

printf("Pochatkovyu massyv\n");

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

{

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

x+=1;

if (z[i]>max) max=z[i];

printf("z[%d]= %f\n",i,z[i]);

}

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

if (z[i]>0) {z[i]=max;

break;

}

printf("kincevyu massyv\n");

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

{printf("z[%d]= %f\n",i,z[i]);}

return 0;

}

Приклад не показуе результату роботи через невдалий збіг обставин, тому ось трохи змінений код і картинка екрану:

#include "stdafx.h"

#include "math.h"

#include <cmath>

Int _tmain(int argc, _tchar* argv[])

{ const int n=7;

float z[n+2],max=0;

int x=1,i;

printf("Pochatkovyu massyv\n");

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

{

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

x+=1;

if (z[i]>max) max=z[i];

printf("z[%d]= %f\n",i,z[i]);

}

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

if (z[i]>0) {z[i]=max;

break;

}

printf("kincevyu massyv\n");

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

{

printf("z[%d]= %f\n",i,z[i]);

}

return 0;

}

6)Pascal

unit Unit1;

Interface

uses

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

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

Memo1: TMemo;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const n=7 ;

var

Form1: TForm1;

max:real; x,i:integer;

z:Array [1..n+2] of real;