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 a:array[1..100]of integer;
i,n,dem:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
dem:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (i mod 2=1) then dem:=dem+1;
writeln(dem);
readln;
end.
var a:array[1..100] of integer;
i,n,S,d:byte;
begin
write(' n = '); readln(n);
for i:=1 to n do begin
write('A[',i,'] = ');
readln(A[i]);
end;
d:=0; S:=0;
for i:=1 to n do if A[i] mod 2 = 0 then begin
d:=d+1;
S:=S+A[i];
end;
write('Dãy có ',d,' phần tử là số chẵn và tổng của chúng là : S = ',S);
readln
end.
Đề bài 1:
uses crt;
var a,b,c:array[1..100]of integer;
k,i,n,max,min,dem,dem1,tam,j,dem2,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
{-------------------------------cau-a--------------------------}
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('gia tri lon nhat cua mang la: ',max);
dem:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem);
b[dem]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem do
write(b[i]:4);
{-----------------------------cau-b--------------------------}
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('gia tri nho nhat cua mang la: ',min);
dem1:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem1);
c[dem1]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem1 do
write(c[i]:4);
{--------------------------cau-c------------------------}
writeln;
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+sqr(a[i]);
writeln('tong binh phuong cac phan tu o vi tri chan la: ',t);
{------------------------cau-d-------------------------------}
writeln('mang duoc sap xep tang dan la: ');
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);
{------------------------cau-e-----------------------}
writeln;
dem2:=0;
for i:=1 to n do
if a[i]=k then inc(dem2);
writeln('so gia tri bang ',k,' trong day la: ',dem2);
readln;
end.
Đề bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,dem,dem1,t,t1,t2:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------cau-a--------------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so luong so chan co trong mang la: ',dem);
{-------------------------------cau-b---------------------------}
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem1);
writeln('so luong so le co trong mang la: ',dem1);
{-----------------------------cau-c--------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac so chan co trong mang la: ',t);
{------------------------------cau-d--------------------------}
t1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t1:=t1+a[i];
writeln('tong cac so le co trong mang la: ',t1);
{------------------------------cau-e-------------------------}
t2:=0;
for i:=1 to n do
t2:=t2+a[i];
writeln('gia tri trung binh cua mang la: ',t2/n:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,t,dem,x;
int main()
{
cin>>n;
t=0;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
t=t+x;
if (x%2==0) dem++;
}
cout<<t<<endl;
cout<<dem;
return 0;
}
Bài 1:
uses crt;
var x,i,t,dem:longint;
tbc:real;
begin
clrscr;
write('nhap x=');readln(x);
t:=0;
dem:=0;
for i:=1 to x do
if x mod i=0 then
begin
t:=t+i;
inc(dem);
end;
tbc:=t/dem;
writeln('trung binh cong cac phan tu la uoc cua ',x,' la: ',tbc:4:2);
readln;
end.
Bài 3:
uses crt;
var a:array[1..100]of integer;
m,n,i:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
write('m='); readln(m);
for i:=1 to n do
if a[i]<0 then a[i]:=m;
for i:=1 to n do
write(a[i]:4);
readln;
end.
Bài 4:
uses crt;
var a:array[1..100]of integer;
n,i,j:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
for i:=1 to n do
for j:=i+1 to n do
if (a[i] mod a[j]=0) then writeln(a[i],' ',a[j]);
if a[j] mod a[i]=0 then writeln(a[j],' ',a[i]);
readln;
end.
Bài 5:
uses crt;
var a:array[1..100]of integer;
n,i,j:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
for i:=1 to n do
for j:=i+1 to n do
if a[i]=sqr(a[j]) then writeln(a[i],' ',a[j]);
if a[j]=sqr(a[i]) then writeln(a[j],' ',a[i]);
readln;
end.
Bài 6:
uses crt;
var a:array[1..100]of integer;
n,i,j:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
for i:=1 to n do
for j:=i+1 to n do
if sqr(a[i])+sqr(a[j])=100 then writeln(a[i],' ',a[j]);
if sqr(a[j])+sqr(a[i])=100 then writeln(a[j],' ',a[i]);
readln;
end.
Bài 7:
uses crt;
var a:array[1..100]of integer;
n,i,t1,t2:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
t1:=0;
t2:=0;
for i:=1to n do
begin
if i mod 2=0 then t1:=t1+a[i]
else t2:=t2+a[i];
end;
if t1=t2 then writeln('thoa man')
else writeln('khong thoa man');
readln;
end.
Bài 8:
uses crt;
var a,b:array[1..100]of integer;
n,i,kt,j,dem:integer;
begin
clrscr;
write('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 i mod 2=0 then
begin
dem:=dem+1;
b[dem]:=a[i];
end;
kt:=0;
for j:=1 to dem-1 do
if a[j]>a[j+1] then kt:=1;
if kt=0 then writeln('cac phan tu o vi tri chan cua day tang dan')
else writeln('cac phan tu o vi tri chan cua day khong tang dan');
readln;
end.
Bài 9:
uses crt;
var a,b,c:array[1..100]of integer;
n,i,j,dem,dem1:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------------------------------}
for i:=1 to n do
begin
if i mod 2=1 then
begin
dem:=dem+1;
b[dem]:=a[i];
end
else begin
dem1:=dem1+1;
c[dem1]:=a[i];
end;
end;
for i:=1 to dem do
write(b[i]:4);
for j:=1 to dem1 do
write(c[j]:4);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem,t:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=1000);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until abs(a[i])<=1000;
end;
for i:=1 to n do
write(a[i]:4);
writeln;
dem:=0;
for i:=1 to n do
if a[i]=0 then inc(dem);
writeln('So phan tu bang 0 la: ',dem);
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('Tong cac phan tu chan la: ',t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem,t: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 cac phan tu chan la: ',dem);
t:=0;
for i:=1 to n do
if i mod 2=1 then t:=t+a[i];
writeln('Tong cac phan tu o vi tri le la: ',t);
readln;
end.
uses crt;
var a:array[1..249] of integer;
i,n,dem,t,j,tam:integer;
kt:boolean;
begin
clrscr;
write('n='); readln(n);
if (n>0) and (n<250) then
begin
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{---------------------------cau-a---------------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so phan tu trong mang co gia tri chan la: ',dem);
{--------------------------cau-b----------------------------}
t:=0;
for i:=1 to n do
if (i mod 2=1) and (a[i] mod 2=0) then t:=t+a[i];
writeln('tong cac phan tu o vi tri le co gia tri chan cua day la: ',t);
{--------------------------cau-c--------------------------------}
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;
kt:=true;
t:=a[2]-a[1];
for i:=1 to n-1 do
if a[i+1]-a[i]<>t then kt:=false;
if kt=true then writeln('day A la cap so cong')
else writeln('day A khong la cap so cong');
end
else writeln('vui long nhap lai');
readln;
end.