LC

viết ct nhập vào n. hãy tìm tất cả các số nguyên xuất hiện trong số n đo

vd

Inputoutput
n=12342  3  23

 

làm bằng pascal nha

 

 

GH
29 tháng 6 2023 lúc 12:46

```pascal
program TimSoNguyenTrongSoN;
uses crt;

procedure TimSoNguyenTrongSoN(n: integer);
var
n_str: string;
so_nguyen_xuat_hien: array of integer;
temp: string;
i, j, so: integer;
begin
n_str := IntToStr(n);
SetLength(so_nguyen_xuat_hien, 0);

for i := 1 to Length(n_str) do
begin
temp := ''
for j := i to Length(n_str) do
begin
temp := temp + n_str[j];
if TryStrToInt(temp, so) then
begin
SetLength(so_nguyen_xuat_hien, Length(so_nguyen_xuat_hien) + 1);
so_nguyen_xuat_hien[Length(so_nguyen_xuat_hien) - 1] := so;
end;
end;
end;

writeln('Cac so nguyen xuat hien trong so ', n, ' la:');
for i := 0 to Length(so_nguyen_xuat_hien) - 1 do
begin
writeln(so_nguyen_xuat_hien[i]);
end;
end;

var
n: integer;
begin
clrscr;
write('Nhap vao so n: ');
readln(n);
TimSoNguyenTrongSoN(n);
readln;
end.
```

Bình luận (1)

Các câu hỏi tương tự
VT
Xem chi tiết
TB
Xem chi tiết
NL
Xem chi tiết
TN
Xem chi tiết
NN
Xem chi tiết
HN
Xem chi tiết
VT
Xem chi tiết
DH
Xem chi tiết
DH
Xem chi tiết