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.
6:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,A[100],i,dem=0;
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1;i<=n; i++)
if (A[i]%2!=0) dem++;
cout<<dem;
return 0;
}
5:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,nn=1e6,A[1000];
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1; i<=n; i++)
nn=min(nn,A[i]);
for (int i=1; i<=n; i++)
if (nn==A[i]) cout<<i<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int A[500],n,i,dem,dem1;
int main()
{
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=n; i>=1; i--) cout<<A[i]<<" ";
cout<<endl;
dem=0;
for (int i=1; i<=n; i++)
if (A[i]<10) dem++;
cout<<dem<<endl;
dem1=0;
for (int i=1; i<=n; i++)
if (A[i]>1)
{
bool kt=true;
for (int j=2; j*j<=A[i]; j++)
if (A[i]%j==0) kt=false;
if (kt==true) dem1++;
}
cout<<dem1;
return 0;
}
uses crt;
var a:array[1..10]of longint;
n,i,t,dem,dem1,dem2,t1:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
t1:=0;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then dem1:=dem+1;
if a[i] mod 2=0 then
begin
dem2:=dem2+1;
t1:=t1+a[i];
end;
end;
writeln(dem1);
writeln(t1/dem2:4:2);
readln;
end.
uses crt;
var a:array[1..10]of longint;
n,i,t,dem,dem1,dem2,t1:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
t1:=0;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then dem1:=dem+1;
if a[i] mod 2=0 then
begin
dem2:=dem2+1;
t1:=t1+a[i];
end;
end;
writeln(dem1);
writeln(t1/dem2:4:2);
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;
}
Câu 1:
uses crt;
var a:array[1..500]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]<0) and (a[i] mod 7=0) then t:=t+a[i];
writeln('Tong cac so am chia het cho 7 la: ',t);
readln;
end.
Câu 2:
uses crt;
var c,a:array[1..10]of integer;
i,kt,j,dem:integer;
begin
clrscr;
for i:=1 to 10 do
begin
write('C[',i,']='); readln(c[i]);
end;
dem:=0;
for i:=1 to 10 do
if c[i]>1 then
begin
kt:=0;
for j:=2 to c[i]-1 do
if c[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=c[i];
end;
end;
if dem=0 then writeln('Trong day khong co so nguyen to')
else begin
writeln('Cac so nguyen to trong day la: ');
for i:=1 to dem do
write(a[i]:4);
end;
readln;
end.
Câu 3:
uses crt;
var d:array[1..200]of integer;
i,k,dem:integer;
begin
clrscr;
write('Nhap k='); readln(k);
for i:=1 to k do
begin
write('D[',i,']='); readln(d[i]);
end;
dem:=0;
for i:=1 to k do
if (a[i] mod 2=0) and (a[i]>=10) then inc(dem);
writeln('So phan tu chan co 2 chu so la: ',dem);
readln;
end.
# Nhap mang
arr = [ ]
for i in range(10):
arr.append(int(input('Nhap phan tu: ')))
# Tinh va xuat ra tong cac phan tu le trong mang tong_cac_phan_tu_le = 0
for x in arr:
if x % 2 != 0:
tong_cac_phan_tu_le += x
print('Tong cac phan tu le trong mang la:', tong_cac_phan_tu_le)
# Nen va xuat ra ngoai man hinh so phan tu duong trong mang so_phan_tu_duong = 0
for x in arr:
if x > 0:
so_phan_tu_duong += 1
print('So phan tu duong trong mang la:', so_phan_tu_duong)
# Tinh va xuat ra man hinh trung binh cong cac phan tu trong mang tong_phan_tu = 0
for x in arr:
tong_phan_tu += x
trung_binh_cong = tong_phan_tu / len(arr)
print('Trung binh cong cac phan tu trong mang la:',trung_binh_cong)
# Tim va xuat ra man hinh gia tri va vi tri cua cac phan tu nho nhat trong mang
min_phan_tu = arr[0]
vi_tri_min_phan_tu = 0
for i in range(1, len(arr)):
if min_phan_tu > arr[i]:
min_phan_tu = arr[i]
vi_tri_min_phan_tu = i
print('Gia tri cua phan tu nho nhat trong mang la:', min_phan_tu)
print('Vi tri cua phan tu nho nhat trong mang la:', vi_tri_min_phan_tu)
#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..6]of integer;
i,dem,t:integer;
begin
clrscr;
for i:=1 to 6 do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to 6 do
if a[i]>0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So phan tu duong la: ',dem);
writeln('Tong cac phan tu duong la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[10],i,n,t;
int main()
{
n=10;
t=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
if (a[i]>3) t=t+a[i];
}
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
cout<<t;
return 0;
}