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;
long long a[5],i,n,t;
int main()
{
n=5;
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++) t+=a[i];
cout<<t<<endl;
for (i=1; i<=n; i++)
if (i%2!=0) cout<<a[i]<<" ";
return 0;
}
tham khảo'
uses crt;
var a:array[1..100]of integer;
i,n,t,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
t:=t+a[i];
inc(dem);
end;
writeln('Tong cac so chan la: ',t);
writeln('So luong so chan la: ',dem);
readln;
end.
Var a:array[1..100] of integer;
i,n,dem,vt,s sc,sl,min:integer;
tbc:real;
Begin
Write('Nhap so luong phan tu n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do s:=s+a[i];
tbc:=s/n;
Writeln('Gia tri trung binh cua mang la ',tbc:10:2);
Write('Cac phan tu lon hon gia tri trung binh la ');
For i:=1 to n do
If a[i]>tbc then write(a[i],' ');
For i:=1 to n do
Begin
If a[i] mod 2 = 0 then sc:=sc+a[i]
Else sl:=sl+a[i];
End;
Writeln('Tong cac phan tu chan la ',sc);
Writeln('Tong cac phan tu le la ',sl);
min:=a[1];
For i:=2 to n do
Begin
If a[i] < min then min:=a[i];
vt:=i;
End;
Writeln('Phan tu nho nhat la ',min,' tai vi tri ',vt);
For i:=1 to n do
If a[i] mod 5 = 0 then dem:=dem+1;
Write('So cac phan tu chia het cho 5 la ',dem);
Readln;
End.
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 x,n,i,nn,t;
int main()
{
cin>>n;
nn=LLONG_MAX;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
t+=x;
nn=min(nn,x);
}
cout<<nn<<" "<<t;
return 0;
}
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if ((x<0) and (x%2!=0)) t=t+x;
}
cout<<t;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[10000],n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
t=t+a[i];
}
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++)
if (a[i] %2==0) dem++;
cout<<dem<<endl;
cout<<t;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem1,dem2: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;
dem1:=0;
for i:=1 to n do
if (a[i]>a[i-1]) and (a[i]>a[i+1]) then dem1:=dem1+1;
dem2:=0;
for i:=1 to n do
if (a[i]<a[i-1]) and (a[i]<a[i+1]) then dem2:=dem2+1;
writeln(dem1);
writeln(dem2);
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)