K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

uses crt;

var i,n:integer;

begin

clrscr;

readln(n);

for i:=1 to n do 

  if i mod 2=1 then write(i:4);

for i:=1 to n do 

  if i mod 2=0 then write(i:4);

readln;

end.

28 tháng 4 2021

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.

28 tháng 4 2021

thank

#include <bits/stdc++.h>

using namespace std;

int A[100],B[100],C[100],kt,n,nn,dem1=0, dem2=0;

int main()

{

cin>>n;

for (int i=1; i<=n; i++)

cin>>A[i];

kt=0;   

nn=INT_MAX;   

for (int i=1; i<=n; i++)     

if (A[i]%2!=0)     

{     

kt=1;     

if (nn>=A[i]) nn=A[i];   

  } 

  if (kt==0) cout<<"khong co";   

else cout<<nn;   

cout<<endl;   

for (int i=1; i<=n; i++)     

if (A[i]%2==0 && A[i]>7)     

cout<<A[i]<<" ";   

cout<<endl;   

for (int i=1; i<=n; i++)     

if (A[i]%2!=0)     

{     

dem1++;     

B[dem1]=A[i];     

}   

for (int i=1; i<=n; i++)   

if (A[i]%2==0)   

{   

dem2++;   

C[dem2]=A[i];   

}   

sort(B,B+dem1+1);   

sort(C,C+dem2+1);   

for (int i=dem1; i>=1; i--)     

cout<<B[i]<<" ";   

for (int i=1; i<=dem2; i++)     

cout<<C[i]<<" ";

}

uses crt;

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

i,n,t,kt,j:integer;

begin

clrscr;

readln(n);

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

t:=0;

for i:=1 to n do 

if a[i] mod 2<>0 then t:=t+a[i];

writeln(t);

for i:=1 to n do 

  if trunc(sqrt(a[i]))=sqrt(a[i]) then write(a[i]:4);

writeln;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt:=0;

for j:=2 to trunc(sqrt(a[i])) do 

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

if kt=0 then write(a[i]:4);

end;

readln;

end.

#include <bits/stdc++.h>

using namespace std;

int A[1000],n,i;

int main()

{

cin>>n;

for (int i=1; i<=n; i++) cin>>A[i];

sort(A+1,A+n+1);

for (int i=1; i<=n; i++)

cout<<A[i]<<" ";

cout<<endl;

for (int i=2; i<=n; i++)

cout<<A[i]-A[i-1]<<endl;

return 0;

}

18 tháng 3 2023

em ko hiểu cho lắm

3 tháng 5 2023

1)

Var array:[1..1000] of integer;

i,n,t:integer;

Begin

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

For i:=1 to n do

Begin

Write('Nhap so thu ',i,' = ');readln(a[i]);

End;

For i:=1 to n do

If a[i] > a[i+1] then

Begin

t:=a[i];

a[i]:=a[i+1];

a[i+1]:=t;

End;

Write('Sap xep tang dan ');

For i:=1 to n do write(a[i]:8);

Readln

End.

3 tháng 5 2023

2)

Var array:[1..1000] of integer;

i,n,t:integer;

Begin

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

For i:=1 to n do

Begin

Write('Nhap so thu ',i,' = ');readln(a[i]);

End;

For i:=1 to n do

If a[i] < a[i+1] then

Begin

t:=a[i];

a[i]:=a[i+1];

a[i+1]:=t;

End;

Write('Sap xep giam dan ');

For i:=1 to n do write(a[i]:8);

Readln

End.

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

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.

4 tháng 5 2023

Program HOC24;

var min,j,i,n,tg: integer;

t: longint;

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

begin

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

for i:=1 to n do 

begin

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

end;

t:=0;

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

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

min:=a[1];

for i:=2 to n do if a[i]<min then min:=a[i];

writeln('So nhat nhat la: ',min);

for i:=1 to n do

for j:=i to n do

if a[i]>a[j] then

begin

tg:=a[i];

a[i]:=a[j];

a[j]:=tg;

end;

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

readln

end.

4 tháng 5 2023

Uses crt;

var  i,n,min,k,e,j: longint

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

begin clrscr;

readln(n);

for i:=1 to n do read(n); readln;

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

for i:=1 to n do if(a[i] mod 2<>0) then k:=k+a[i];

min:=a[i];

for i:=1 to n do if(min>a[i]) then min:=a[i];

writeln(min);

for i:=1 to n-1 do
for j:=i+1 to n do if a[j] <=a[i] then
begin e:= a[i];

a[i]:=a[j];

a[j]:=e; end;
for i:=1 to n do write(a[i],';');

readln;

end.