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.
#include <iostream>
#include <string>
#define N 5
using namespace std;
int count_flat = 0;
struct Flat {
int n_rooms;
int square;
int floor;
string address;
double price;
void PrintInfo() {
cout << "\nКоличество комнат: " << n_rooms << "\nПлощадь " << square << "\nЭтаж:" << floor << "\nАдрес " << address << "\nЦена: " << price;
}
void InputInfo() {
cout << "Количество комнат: ";
cin >> n_rooms;
cout << "Площадь: ";
cin >> square;
cout << "Этаж: ";
cin >> floor;
cout << "Адрес: ";
getline(cin, address);
cout << "Цена: ";
cin >> price;
}
void PrintChecksInfo(int number) {
if (number >= price) {
count_flat++;
PrintInfo();
}
}
};
signed main() {
setlocale(LC_ALL, "Rus");
int choice;
Flat mas[N];
for (int i = 0; i < N; i++)
mas[i].InputInfo();
cout << "Введите стоимость: ";
cin >> choice;
for (int i = 0; i < N; i++) {
mas[i].PrintChecksInfo(choice);
}
if (count_flat <= 0)
cout << "Таких квартир нет!";
return 0;
}