Long ca ca

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

 

 

Gia Huy
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.
```


Các câu hỏi tương tự
Vy Nguyễn Hà Thảo
Xem chi tiết
Thành Tân B1-
Xem chi tiết
Nguyễn Lê
Xem chi tiết
Thảo Ngọc
Xem chi tiết
Nguyễn Trần Hồng Ngọc
Xem chi tiết
Huyền Diệu Nguyễn
Xem chi tiết
Vũ Tú
Xem chi tiết
Địêp Hòang Thị Hồ
Xem chi tiết
Diễm Phạm Thị Hồng
Xem chi tiết