Chương trình con và lập trình có cấu trúc

bui pham phuong Uyen

Giải giúp với ạ.Môn Tin thật khó khăn.

 

undefined

Nguyễn Lê Phước Thịnh
17 tháng 4 2021 lúc 13:25

uses crt;

const fi='ktt2.inp'

var f1:text;

s:string;

a:array[1..100]of integer;

n,i,x,dem,t,kt,kt1,j,max,kt2:integer;

begin

clrscr;

assign(f1,fi);reset(f1);

readln(f1,n,x);

readln(f1,s);

for i:=1 to n do 

  read(f1,a[i]);

t:=0;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt:=0;

for j:=2 to a[i]-1 do 

 if a[i] mod j=0 then kt:=1;

if kt=0 then t:=t+a[i];

end;

writeln('Tong cac so nguyen to la: ',t);

dem:=0;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt1:=0;

for j:=2 to a[i]-1 do 

  if a[i] mod j=0 then kt1:=1;

if (kt1=0) and (a[i]<x) then inc(dem);

end;

writeln('So luong so nguyen to nho hon ',x,' la: ',dem);

max:=0;

for i:=1 to n do

  if a[i]>1 then 

begin

kt2:=0;

for j:=2 to a[i]-1 do 

  if a[i] mod j=0 then kt2:=1;

if (kt2=0) and (max<a[i]) then max:=a[i];

end;

if max=0 then writeln('Khong co so nguyen to nao trong day')

else writeln('So nguyen to lon nhat la: ',max);

write('Xau ',s,' theo thu tu nguoc la: ');

d:=length(s);

for i:=d downto 1 do

  write(s[i]);

writeln;

close(f1);

readln;

end.

Bình luận (0)

Các câu hỏi tương tự
duong nguyenvan
Xem chi tiết
Nguyễn Thị Thanh Nhàn
Xem chi tiết
Minh Thư
Xem chi tiết
Bùi Thị Ngọc
Xem chi tiết
Đạt Tạ
Xem chi tiết