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;
n,i,k,dem,dem1: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);
dem:=0;
dem1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then inc(dem);
if a[i] mod k=0 then inc(dem1);
end;
writeln('So phan tu chan la: ',dem);
writeln('So phan tu chia het cho ',k,' la: ',dem1);
readln;
end.
Bài 2:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,ln,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
ln=a[1];
nn=a[1];
for (i=2; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<ln<<" "<<nn;
}
uses crt;
var a:array[1..100]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 3=0) and (i mod 2=0) then t:=t+a[i];
writeln('Tong cac so chia het cho 3 o vi tri chan la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[100],n,i,t,t1,dem,dem1;
//chuongtrinhcon
bool ktnt(long long x)
{
if (x<=1) return(false);
for (int i=2; i*i<=x; i++)
if (x%i==0) return(false);
return true;
}
//chuongtrinhchinh
int main()
{
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i];
}
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++) if (a[i]%2==0) t=t+a[i];
cout<<t<<endl;
dem=0;
for (i=1; i<=n; i++) if (a[i]%3==0) dem++;
cout<<dem<<" ";
t1=0;
dem1=0;
for (i=1; i<=n; i++)
if (a[i]%2!=0)
{
t1+=a[i];
dem1++;
}
cout<<fixed<<setprecision(2)<<(t1*1.0)/(dem1*1.0)<<endl;
for (i=1; i<=n; i++)
if (ktnt(a[i])==true) cout<<a[i]<<" ";
return 0;
}
Bài 2:
uses crt;
var x,i,n,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
writeln(dem);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,dem,t;
int main()
{
cin>>n;
dem=0;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) t+=x;
if (x%3==0) dem++;
}
cout<<"Tong cac so chan la: "<<t<<endl;
cout<<"So luong phan tu chia het cho 3 la: "<<dem;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,t,j,tam:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:5);
writeln;
writeln('Cac so duong la: ');
for i:=1 to n do if (a[i]>0) then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln(t);
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.
Program HOC24;
var a: array[1..1000] of integer;
i,n,d: integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
d:=0;
for i:=1 to n do if a[i] mod 3=0 then d:=d+1;
write('Co ',d,' so chia het cho 3');
readln
end.