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.
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "stdafx.h"
#include "stdio.h"
#include <time.h>
#include <stdlib.h>
class vector
{
private:
int* m;
int size;
public :
vector(int n = 0);
vector(const vector &vector2);
~vector();
};
vector::vector( int n )
{
if (n < 0) n = 0;
size = n;
m = new int[n];
if(!m)
printf("Error");
else
m = NULL;
}
vector::vector(const vector &vector2)
{
size = vector2.size;
m = new int [size];
for(int i = 0; i<size;i++)
m[i] = vector2.m[i];
printf("Hello world !");
}
vector::~vector()
{
delete[] m;
}
vector(int *m, int size)
{
srand(time(NULL))
if(!m)
printf("error")
else
for(int i = 0; i < size; i++)
m[i] = rand()% 99;
}
int main()
{
vector v1(45),
system("pause");
return 0;
}
Так?