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.
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[1000];
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
sort(a+1,a+n+1);
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
Bài 1:
uses crt;
var a:array[1..200]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 5=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 5 la: ',t);
readln;
end.
Bài 2:
uses crt;
var st:string;
d,i:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
for i:=1 to d do
if st[i]=#32 then delete(st,i,1);
writeln(st);
readln;
end.
uses crt;
var n,i,k,dem:integer;
a:array[1..100]of integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('So phan tu chan trong day so la: ',dem);
write('Nhap so k='); readln(k);
kt:=0;
for i:=1 to n do
if a[i]=k then kt:=i;
if kt=0 then writeln('Khong co phan tu nao trong day bang ',k)
else writeln('Trong day co phan tu bang ',k);
readln;
end.
Bai 2:
uses crt;
var a:array[1..100]of integer;
i,n,t,nn:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
nn:=a[1];
for i:=1 to n do
if nn>a[i] then nn:=a[i];
write(nn);
readln;
end.
Câu 1:
#include <bits/stdc++.h>
using namespace std;
long long i,n,k,dem,x;
int main()
{
cin>>n;
cin>>k;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x==k) dem++;
}
cout<<dem;
return 0;
}
program BaiToanMang;
var
A: array[1..100] of integer;
N, i, demChan, tongLeChia3: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(N);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to N do
begin
write('a[', i, ']= ');
readln(A[i]);
end;
tongLeChia3 := 0;
for i := 1 to N do
begin
if (A[i] mod 2 = 1) and (A[i] mod 3 = 0) then
begin
tongLeChia3 := tongLeChia3 + A[i];
end;
end;
writeln('Tong cac so le chia het cho 3: ', tongLeChia3);
demChan := 0;
for i := 2 to N do
begin
if (A[i] mod 2 = 0) and (i mod 2 = 1) then
begin
demChan := demChan + 1;
end;
end;
writeln('So phan tu chan o vi tri le: ', demChan);
writeln('Cac so chan chia het cho 5: ');
for i := 1 to N do
begin
if (A[i] mod 2 = 0) and (A[i] mod 5 = 0) then
begin
write(A[i], ' ');
end;
end;
end.
ko bt đúng ko ko dùng pascal nhiều
Câu 1:
uses crt;
var a:array[1..100]of integer;
n,i,tl,tc:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i];
if a[i] mod 2=1 then tl:=tl+a[i];
end;
writeln('tong so nguyen chan cua day la: ',tc);
writeln('tong so nguyen le cua day la: ',tl);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
n,i:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------------xu-ly-----------------------------}
writeln('cac so nguyen am co trong day la: ');
for i:=1 to n do
if a[i]<0 then write(a[i]:4);
readln;
end.
Câu 3:
uses crt;
var a:array[1..100]of integer;
n,i,t:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------------xu-ly-----------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln('tong cac phan tu chia het cho 3 la: ',t);
readln;
end.
Câu 4:
uses crt;
var a,vt:array[1..100]of integer;
n,i,t,dem,j:integer;
min:int64;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
min:=maxint;
for i:=1 to n do
if min>a[i] then min:=a[i];
dem:=0;
for i:=1 to n do
if a[i]=min then
begin
inc(dem);
vt[dem]:=i;
end;
writeln('so nho nhat la: ',min);
writeln('vi tri cua no trong day lan luot la: ');
for j:=1 to dem do
write(vt[j]:4);
readln;
end.
Câu 5:
uses crt;
var a,vt:array[1..100]of integer;
n,i,j,tam:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
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 so giam dan la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
uses crt;
var a:array[1..199]of integer;
n,i,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------cau-1--------------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=1 then t:=t+a[i];
writeln('tong cac phan tu le trong mang la: ',t);
{---------------------------------cau-2------------------------------}
writeln('cac phan tu vua nhap co chi so chan la: ');
for i:=1 to n do
if i mod 2=0 then write(a[i]:4);
readln;
end.
uses crt;
var a:array[1..200]of longint;
t,n,i:longint;
begin
clrscr;
n:=200;
t:=0;
for i:=1 to 200 do
begin
write('a[',i,']='); readln(a[i]);
if a[i] mod 2=1 then t:=t+a[i];
end;
writeln('tong cac phan tu le trong day la: ',t);
readln;
end.
uses crt;
var i:integer;
tong: longint;
a: array [1..200] of integer;
begin
clrscr;
tong:= 0;
for i:= 1 to 200 do
begin
write('Phan tu ',i,': ');
readln(a[i]);
if a[i] mod 2 <> 0 then
tong:= tong + a[i];
end;
write('Tong cac phan tu le: ',tong);
readln
end.