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.
1.
Program Tim_Max;
Var A:Array[1..255] of Integer;
i, n, Max: Integer;
Begin
Write('Nhap n: '); Readln(n);
For i := 1 to n do
Begin
Write('Nhap phan tu A[',i,'] = '); Readln(A[i]);
End;
Max := A[1];
For i := 2 to n do if A[i]>Max then Max := A[i];
Write('Phan tu lon nhat la :',Max);
Readln
End.
2.
Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,j,Tam:Integer;
Begin
{Nhập mảng}
Write('Nhap N='); Readln(N);
For i:=1 To N Do
Begin
Write('A[',i,']='); Readln(A[i]);
End;
{Sắp xếp}
For i:=1 To N-1 Do
For j:=i+1 To N Do
If A[i]>A[j] Then
Begin
Tam:=A[i]; A[i]:=A[j]; A[j]:=Tam;
End;
{In kết quả ra màn hình}
Writeln('Ket qua sau khi sap xep:');
For i:=1 To N Do Write(A[i]:5);
Readln;
End.
3.
Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,x:Integer;
Function TimKiem(x, N: Integer; A:Mang):Integer;
Var i:Integer;
Begin
I:=1;
While (I <= N) and (X<>A[I]) do I:=I+1; {{{{tại sao lại phải làm như bước này, tại sao lại lấy i đi so sánh với N}}}}
If I <= N Then Timkiem:=I Else Timkiem:=0;
End;
Begin
{Nhập mảng}
Write(‘Nhap N=’); Readln(N);
For i:=1 To N Do
Begin
Write(‘A[‘,i,’]=’); Readln(A[i]);
End;
Write(‘Nhap X=’); Readln(x);
{Kết quả tìm kiếm}
If TimKiem(X,N,A)<>0 Then
Writeln(‘Vi tri cua X trong mang la:’, TimKiem(X,N,A))
Else Writeln(‘X khong co trong mang.’);
Readln;
End.
câu 1 tham khảo cái này nhé
Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,Max:Integer;
Begin
Write('Nhap N='); Readln(N);
For i:=1 To N Do
Begin
Write('A[',i,']='); Readln(A[i]);
End;
Max:=A[1];
For i:=2 To N Do
If Max<A[i] Then Max:=A[i];
Writeln('Phan tu lon nhat cua mang:', Max);
Readln;
End.
Var a:array[1..1000] of integer;
i,m,tam:integer;
Begin
Write('m = ');readln(m);
For i:=1 to m do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to m do
If a[i] < a[i+1] then
Begin
tam:=a[i];
a[i]:=a[i+1];
a[i+1]:=tam;
End;
Write('Mang sau khi sap xep: ');
For i:=1 to m do
Write(a[i]:8);
Readln;
End.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,kt,max,x,j,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Mang ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('Day tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
write('Nhap x='); readln(x);
max:=0;
kt:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]<=x) then
begin
if max<a[i] then max:=a[i];
kt:=1;
end;
if kt=0 then writeln('Trong day khong co so le')
else writeln('So chan lon nhat khong vuot qua ',x,' la: ',max);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long b[15],i,n,k,dem;
bool kt;
int main()
{
n=15;
for (i=1; i<=n; i++) cin>>b[i];
for (i=1; i<=n; i++) cout<<b[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++) if (b[i]%2==0) dem++;
cout<<"So so chan la: "<<dem<<endl;
cin>>k;
kt=false;
for (i=1; i<=n; i++) if (b[i]==k)
{
cout<<i<<" ";
kt=true;
}
if (kt==false) cout<<"Khong co k trong day";
else cout<<endl;
sort(b+1,b+n+1);
for (i=1; i<=n; i++) cout<<b[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,k,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
cin>>k;
dem=0;
for (i=1; i<=n; i++)
if (a[i]==k) dem++;
cout<<dem;
return 0;
}
uses crt;
var a:array[1..200]of integer;
n,i,k,t,t1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
cout<<"Cac so duong la: ";
for (i=1; i<=n; i++) if (a[i]>0) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++) if (a[i]%2==0) cout<<a[i]<<" ";
for (i=1; i<=n; i++) if (a[i]%2!=0) cout<<a[i]<<" ";
return 0;
}
uses crt;
var a:array[1..250]of integer;
i,n,tam,j:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do
write(a[i]:4);
readln;
end.