Var ar:array[1..n] of integer; ar2:array[1..n] of integer; i,k:integer;
function prost(a:integer):boolean; var i:integer; b:boolean; begin b:=true; for i:=2 to a div 2 do if a mod i=0 then begin; b:=false; break; end; if a=1 then b:=false; prost:=b; end;
begin; randomize; k:=0; for i:=1 to n do begin; ar[i]:=random(101); write(ar[i]:4); end; writeln; for i:=1 to n do if prost(ar[i]) then begin; inc(k); ar2[k]:=ar[i]; write(ar2[k]:4); end; end.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a,b,c,p,s;
struct {
float ax,ay,bx,by,cx,cy;
} ABC;
cout<<" задайте координаты точек"<<endl;
cout<<" ax "<<" ay "<<" bx "<<" by "<<" cx "<<" cy";
cout<<endl;
cin>>ABC.ax>>ABC.ay>>ABC.bx>>ABC.by>>ABC.cx>>ABC.cy;
// вычисление длин сторон
a=sqrt(pow((ABC.bx-ABC.ax),2)+pow((ABC.by-ABC.ay),2));
b=sqrt(pow((ABC.cx-ABC.bx),2)+pow((ABC.cy-ABC.by),2));
c=sqrt(pow((ABC.cx-ABC.ax),2)+pow((ABC.cy-ABC.ay),2));
p=(a+b+c)/2;
// проверка, что можно составить треугольник
if (((p-a)>0) && ((p-b)>0) && ((p-c)>0))
cout<<"точки образуют треугольник"<<endl;
else cout<<"точки лежат на одной прямой"<<endl;
system("pause");
return(0);
}
n=5;
Var
ar:array[1..n] of integer;
ar2:array[1..n] of integer;
i,k:integer;
function prost(a:integer):boolean;
var i:integer;
b:boolean;
begin
b:=true;
for i:=2 to a div 2 do
if a mod i=0 then
begin;
b:=false;
break;
end;
if a=1 then b:=false;
prost:=b;
end;
begin;
randomize;
k:=0;
for i:=1 to n do
begin;
ar[i]:=random(101);
write(ar[i]:4);
end;
writeln;
for i:=1 to n do
if prost(ar[i]) then
begin;
inc(k);
ar2[k]:=ar[i];
write(ar2[k]:4);
end;
end.