Những câu hỏi liên quan
Linh hoa
Xem chi tiết
dinhnguyentuhuy
Xem chi tiết
Nguyễn Lê Phước Thịnh
30 tháng 1 2021 lúc 22:42

uses crt;

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

i,n,t,t1,t2,t3,min,max:integer;   

kt:boolean;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

begin     

write('A[',i,']='); readln(a[i]); 

end;

writeln('Day so ban vua nhap la: ');

for i:=1 to n do 

write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

t:=t+a[i];

kt:=true;

for i:=2 to trunc(sqrt(t)) do 

if t mod i=0 then     

begin       

kt:=false;       

break;     

end;

writeln('Tong cua day so la: ',t);

if (kt=true) and (t>1) then writeln(t,' la so nguyen to')

else writeln(t,' khong la so nguyen to');

writeln('Cac so o vi tri le cua day so la: ');

t1:=0;

for i:=1 to n do 

if i mod 2=1 then     

begin       

write(a[i]:4);       

t1:=t1+a[i];     

end;

writeln;

writeln('Tong cac so o vi tri le cua day so la: ',t1);

if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')

else writeln(t1,' khong la so chinh phuong');

writeln('Cac so o vi tri chan cua day so la: ');

t2:=0;

for i:=1 to n do 

if i mod 2=0 then     

begin       

write(a[i]:4);       

t2:=t2+a[i];     

end;

writeln;

writeln('Tong cac so o vi tri chan cua day so la: ',t2);

t3:=0;

for i:=1 to t2 do 

if t2 mod i=0 then t3:=t3+i;

if t3=t2 then writeln(t2,' la so hoan hao')

else writeln(t2,' khong la so hoan hao');

max:=a[1];

min:=a[1];

for i:=1 to n do 

begin     

if max<a[i] then max:=a[i];     

if min>a[i] then min:=a[i]; 

end;

writeln('So lon nhat cua day la: ',max);

writeln('So nho nhat cua day la: ',min);

writeln('Tong cua so lon nhat va so nho nhat la: ',max+min);

readln;

end.

dinhnguyentuhuy
Xem chi tiết
Nguyễn Lê Phước Thịnh
28 tháng 1 2021 lúc 20:43

uses crt;

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

n,i,t,kt,j,t1,t2,t3,max,min:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

begin

write('A[',i,']='); readln(a[i]);

end;

writeln('Day so ban vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln('Tong cua day so vua nhap la: ',t);

kt:=0;

for i:=2 to trunc(sqrt(t)) do 

  if t mod i=0 then

begin

kt:=1;

break;

end;

if (kt=0) and (t>1) then writeln(t,' la so nguyen to');

else writeln(t,' khong la so nguyen to');

t1:=0;

writeln('Cac so o vi tri le cua day la: ');

for i:=1 to n do 

  if i mod 2=1 then 

begin

write(a[i]:4);

t1:=t1+a[i];

end;

writeln;

writeln('Tong cac so o vi tri le la: ',t1);

if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')

else writeln(t1,' khong la so chinh phuong');

t2:=0;

writeln('Cac so o vi tri chan la: ');

for i:=1 to n do 

  if i mod 2=0 then 

begin

write(a[i]:4);

t2:=t2+a[i];

end;

writeln;

writeln('Tong cac so o vi tri chan la: ',t2);

t3:=0;

for i:=1 to t2 do 

if t2 mod i=0 then t3:=t3+i;

if t3=t2 then writeln(t2,' la so hoan hao')

else writeln(t2,' khong la so hoan hao');

max:=a[1];

min:=a[1];

for i:=1 to n do 

begin

if max<a[i] then max:=a[i];

if min>a[i] then min:=a[i];

end;

writeln('Gia tri lon nhat la: ',max);

writeln('Gia tri nho nhat la: ',min);

writeln('Tong cua hai so lon nhat va nho nhat la: ',max+min);

readln;

end.

Vương Tuấn Đạt
Xem chi tiết
Nguyễn Lê Phước Thịnh
3 tháng 3 2021 lúc 13:26

uses crt;

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

i,n,dem,dem1,dem2,j,kt:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

dem:=0;

writeln('Cac so le la: ');

for i:=1 to n do 

if a[i] mod 2<>0 then 

begin

write(a[i]:4);

inc(dem);

end;

writeln;

writeln('Co ',dem,' so le');

dem1:=0;

writeln('Cac so chan la: ');

for i:=1 to n do 

  if a[i] mod 2=0 then

begin

write(a[i]:4);

inc(dem1);

end;

writeln;

writeln('Co ',dem1,' so chan');

dem2:=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 inc(dem2);

end;

writeln('Co ',dem2,' so nguyen to');

readln;

end.

Asuna
Xem chi tiết

Dưới đây là mã chương trình Pascal để sắp xếp dãy số theo yêu cầu đã cho:

```pascal
program sorting;

const
MAX_N = 1000;

var
N, i, j, temp: integer;
arr: array[1…MAX_N] of integer;
oddArr, evenArr: array[1…MAX_N] of integer;
oddCount, evenCount: integer;
inputFile, outputFile: text;

begin
// Mở file input và đọc dữ liệu
assign(inputFile, 'sorting.inp');
reset(inputFile);
readln(inputFile, N);
for i := 1 to N do
read(inputFile, arr[i]);
close(inputFile);

// Sắp xếp mảng theo yêu cầu
oddCount := 0;
evenCount := 0;
for i := 1 to N do
begin
if arr[i] mod 2 = 1 then
begin
oddCount := oddCount + 1;
oddArr[oddCount] := arr[i];
end
else
begin
evenCount := evenCount + 1;
evenArr[evenCount] := arr[i];
end;
end;

// Sắp xếp mảng số lẻ tăng dần
for i := 1 to oddCount - 1 do
for j := i + 1 to oddCount do
if oddArr[i] > oddArr[j] then
begin
temp := oddArr[i];
oddArr[i] := oddArr[j];
oddArr[j] := temp;
end;

// Sắp xếp mảng số chẵn giảm dần
for i := 1 to evenCount - 1 do
for j := i + 1 to evenCount do
if evenArr[i] < evenArr[j] then
begin
temp := evenArr[i];
evenArr[i] := evenArr[j];
evenArr[j] := temp;
end;

// Mở file output và ghi kết quả
assign(outputFile, 'sorting.out');
rewrite(outputFile);
for i := 1 to oddCount do
write(outputFile, oddArr[i], ' ');
writeln(outputFile);
for i := 1 to evenCount do
write(outputFile, evenArr[i], ' ');
close(outputFile);
end.
```

Bạn có thể sao chép mã chương trình trên vào một tệp tin có tên `sorting.pas`, sau đó tạo một tệp tin `sorting.inp` và nhập dữ liệu theo định dạng đã cho. Chạy chương trình và kết quả sẽ được ghi vào tệp tin `sorting.out`.

Phạm Dương Phúc Khang
21 tháng 1 lúc 22:55

var i,n:longint; a:array[1..1000] of longint;

begin

readln(n);

for i:=1 to n do read(a[i]);

for i:=1 to n do

     if a[i] mod 2=0 then 

         begin

              inc(k);

              b[k]:=a[i];

         end

else

begin

inc(t);

c[t]:=a[i];

end;

for i:=1 to k-1 do

for j:=i+1 to k do

if b[i]<b[j] then

begin

d:=b[i];

b[i]:=b[j];

b[j]:=d;

end;

for i:=1 to  t-1 do

for j:=i+1 to t do

if c[i]>c[j] then

begin

d:=c[i];

c[i]:=c[j];

c[j]:=d;

end;

for i:=1 to k do write(b[i],' ');

for i:=1 to t do write(c[i],' ');

end.

nguyensonbd
Xem chi tiết
Nguyen Hung
28 tháng 4 2021 lúc 21:04

Program Tin_hoc;

Uses crt;

Var i,tam,n,chan,le,j:integer;

      a,daychan,dayle:array[1..10000] of integer;

Begin

clrscr;

Write('Nhap n: ');readln(n);

chan:=0;le:=0;

Writeln('Nhap ',n,' phan tu cua mang:');

For i:= 1 to n do 

Begin

write('A[',i,'] = ');

Readln(a[i]);

If a[i] mod 2 = 0 then 

  Begin

  inc(chan);

  daychan[chan]:=a[i];

  end

else

  Begin

  inc(le);

  dayle[le]:=a[i];

  End;

End;

For i:= 1 to chan do

  for j:= i to chan do If daychan[i]>daychan[j] then 

  Begin

  tam:=daychan[i];

  daychan[i]:=daychan[j];

  daychan[j]:=tam;

  End;

For i:= 1 to le do

  for j:= i to le do If dayle[i]<dayle[j] then 

  Begin

  tam:=dayle[i];

  dayle[i]:=dayle[j];

  dayle[j]:=tam

  End;

Writeln('Day sau khi sap xep:');

For i:= 1 to chan do write(daychan[i],'  ');

For i:= 1 to le do write(dayle[i],'  ');

Readln;

End.

Nguyen Huynh Tuong Vy
Xem chi tiết
Minh Lệ
13 tháng 3 2021 lúc 13:36

Program HOC24;

var a: array[1..32000] of integer;

i,n,tg,c,l: integer;

tc,tl: longint;

begin

write('Nhap N: '); readln(n);

c:=0; l:=0; tc:=0; tl:=0;

for i:=1 to n do

begin

write('Nhap so thu ',i,': '); readln(a[i];

if a[i] mod 2=0 then

begin

c:=c+1;

tc:=tc+a[i];

end;

if a[i] mod 2=1 then

begin

l:=l+1;

tl:=tl+a[i];

end;

end;

write('Day da sap xep: ');

for i:=1 to n do if a[i] mod 2=1 then write(a[i],' ');

for i:=1 to n do if a[i] mod 2=0 then write(a[i],' ');

writeln;

wirteln('Co ',l,' so le');

writeln('Co ',c,' so chan');

writeln('Tong cac so le la: ',tl);

writeln('Tong cac so chan la:', tc);

readln

end.

Chouu11
Xem chi tiết
Kiều Vũ Linh
16 tháng 5 2023 lúc 7:39

Var n,sc,sl,i:longint;

Begin

Write('N = ');readln(n);

Write('Cac so tu 1 den ',n,' la ');

For i:=1 to n do

Write(i:8);

Writeln;

For i:=1 to n do

Begin

If i mod 2 = 0 then sc:=sc+i

Else sl:=sl+i;

End;

Writeln('Tong cac so chan la ',sc);

Write('Tong cac so le la ',sl);

Readln

End.

Hiep Ho
Xem chi tiết