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.
Câu 4:
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
char x;
int main()
{
getline(cin,st);
d=st.length();
cout<<st<<endl;
cin>>x;
dem=0;
for (i=0; i<=d-1; i++) if (st[i]==x) dem++;
cout<<dem;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
char x;
int main()
{
getline(cin,st);
d=st.length();
cout<<st<<endl;
cin>>x;
dem=0;
for (i=0; i<=d-1; i++) if (st[i]==x) dem++;
cout<<dem;
return 0;
}
# 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,i,n,t1,dem,t;
int main()
{
cin>>n;
dem=0;
t=0;
t1=0;
for (i=1; i<=n; i++)
{
cin>>x;
t+=x;
if (x>0)
{
dem++;
t1+=x;
}
}
cout<<"So phan tu duong la: "<<dem<<endl;
cout<<"Tong cac so duong la: "<<t1<<endl;
cout<<"Trung binh cong cua day la: "<<fixed<<setprecision(2)<<(t*1.0)/(n*1.0)<<endl;
cout<<"Trung binh cac so duong la: "<<fixed<<setprecision(2)<<(t1*1.0)/(dem*1.0);
return 0;
}
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]<0) and (i mod 2=1) then t:=t+a[i];
writeln('Tong cac phan tu am tai vi tri le la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int B[100],i,n,t=0,s=1;
int main()
{
cin>>n;
for (int i=1; i<=n; i++) cin>>B[i];
for (int i=1; i<=n; i++)
{
if (i%2==0) s*=A[i];
else t+=A[i];
}
cout<<t<<" "<<s;
}
Câu 1:
program mangsonguyen;
var
a: array[1..100] of integer;
i, n: integer;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Mang vua nhap la:');
for i := 1 to n do
write(a[i], ' ');
end.
Câu 2:
program trungbinhcong;
var
a: array[1..100] of integer;
i, n, k, sum: integer;
avg: real;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Nhap so k: ');
readln(k);
sum := 0;
for i := 1 to n do
begin
if a[i] <= k then
sum := sum + a[i];
end;
if sum > 0 then
begin
avg := sum / n;
writeln('Trung binh cong cac phan tu co gia tri <= ', k, ' la: ', avg:0:2);
end
else
begin
writeln('Khong co phan tu nao co gia tri <= ', k);
end;
end.
Câu 3:
program DemSoNguyenTo;
var
a: array [1..100] of integer;
i, j, n, count: integer;
laSoNguyenTo: boolean;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
write('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
count := 0;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
laSoNguyenTo := true;
for j := 2 to (a[i] div 2) do
begin
if (a[i] mod j = 0) then
begin
laSoNguyenTo := false;
break;
end;
end;
if laSoNguyenTo and (a[i] > 1) then
begin
writeln(a[i]);
count := count + 1;
end;
end;
writeln('Tong so cac so nguyen to la: ', count);
readln;
end.
uses crt;
var a:array[1..200]of integer;
i,t:integer;
begin
clrscr;
for i:=1 to 200 do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac phan tu le nho hon 200 la: ');
for i:=1 to n do
if (a[i] mod 2<>0) and (a[i]<200) then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if (50<a[i]) and (a[i]<80) then t:=t+sqr(a[i]);
writeln('Tong binh phuong cac phan tu thuoc khoang (50;80) la: ',t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem,t,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>0 then
begin
dem:=dem+1;
t:=t+a[i];
end;
writeln('So luong phan tu duong la: ',dem);
writeln('Tong cac phan tu duong la: ',t);
writeln('Trung binh cac phan tu duong la: ',t/dem:4:2);
readln;
end.
uses crt;
var a:array[1..100]of integer;
n,dem,i,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;
t:=0;
for i:=1 to n do
if i mod 2=1 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('Trung binh cong cac phan tu o vi tri le la: ',t/dem:4:2);
readln;
end.