function f(x: real): real; begin f:=0.5*x*cos(2*x); end;
// l (logical) - логические координаты // s (screen) - физические координаты procedure drawGraph(x1,x2,y1,y2: real; f: FUN); var xl,xl0,wl,yl,yl0,hl: real; xs0,ws,ys0,hs: integer; function LtoSx(xl: real): integer; begin Result:=round(ws/wl*(xl-xl0)+xs0); end; function LtoSy(yl: real): integer; begin Result:=round(hs/hl*(yl-yl0)+ys0); end; function StoLx(xs: integer): real; begin Result:=wl/ws*(xs-xs0)+xl0; end; var xi: integer; begin // drawGraph xs0:=0; ys0:=WindowHeight; ws:=WindowWidth; hs:=WindowHeight; xl0:=x1; yl0:=y1; wl:=x2-x1; hl:=-(y2-y1); MoveTo(xs0,LtoSy(f(StoLx(xs0; for xi:=xs0+1 to xs0+ws do LineTo(xi,LtoSy(f(StoLx(xi; end;
begin // program SetWindowCaption('График функции'); drawGraph(-12,12,-23,23,f); end.
uses GraphABC;
type FUN = function (x: real): real;
function f(x: real): real;
begin
f:=0.5*x*cos(2*x);
end;
// l (logical) - логические координаты
// s (screen) - физические координаты
procedure drawGraph(x1,x2,y1,y2: real; f: FUN);
var
xl,xl0,wl,yl,yl0,hl: real;
xs0,ws,ys0,hs: integer;
function LtoSx(xl: real): integer;
begin
Result:=round(ws/wl*(xl-xl0)+xs0);
end;
function LtoSy(yl: real): integer;
begin
Result:=round(hs/hl*(yl-yl0)+ys0);
end;
function StoLx(xs: integer): real;
begin
Result:=wl/ws*(xs-xs0)+xl0;
end;
var xi: integer;
begin // drawGraph
xs0:=0; ys0:=WindowHeight;
ws:=WindowWidth;
hs:=WindowHeight;
xl0:=x1;
yl0:=y1;
wl:=x2-x1;
hl:=-(y2-y1);
MoveTo(xs0,LtoSy(f(StoLx(xs0;
for xi:=xs0+1 to xs0+ws do
LineTo(xi,LtoSy(f(StoLx(xi;
end;
begin // program
SetWindowCaption('График функции');
drawGraph(-12,12,-23,23,f);
end.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n;
cout<<"Введите количество элементов массива."<<endl;
cin>>n;
int mas1[n];
int mas2[n];
for(int i=0; i<n; i++){
mas1[i] = rand()%100; //Заполняем массив случайными числами от 0 до 100
if(mas1[i]%10 == 4) {
mas2[i]=mas1[i]/2;
cout<<"Замена! ";
}
else {cout<<"\t";
mas2[i]=mas1[i];
}
cout<<mas1[i]<<'\t'<<mas2[i]<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}