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.
Bài 1:
uses crt;
var a:array[1..20]of integer;
i,n,t:integer;
begin
clrscr;
write('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 i mod 2=1 then t:=t+sqr(a[i]);
writeln('tong binh phuong cac phan tu o vi tri le la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (1<=n) and (n<=1000);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Mang ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
dem:=0;
for i:=1 to n do
if a[i] mod 3=0 then inc(dem);
writeln('So phan tu chia het cho 3 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)
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.
Var a:array[1..100] of integer;
i,s:integer;
Begin
For i:=1 to 100 do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
If a[i] mod 2 <> 0 then s:=s+a[i];
End;
Write('Tong la ',s);
Readln;
End.
uses crt;
var a,b,c,d:array[1..100]of integer;
n,i,dem,t,max,min,j,dem1,kt,dem2,dem3,kt1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Phan tu dau tien la: ',a[1]);
writeln('Phan tu cuoi cung la: ',a[n]);
dem:=0;
for i:=1 to n do
if a[i] mod 4=0 then inc(dem);
writeln('So luong phan tu chia het cho 4 la: ',dem);
t:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]>10) then t:=t+a[i];
writeln('Tong cac so chan va lon hon 10 la: ',t);
dem1:=0;
for i:=1 to n do
if sqrt(a[i])=trunc(sqrt(a[i])) then
begin
inc(dem1);
b[dem1]:=a[i];
end;
writeln;
writeln('So luong so chinh phuong trong mang la: ',dem1);
if dem1>0 then
begin
writeln('Cac so chinh phuong co trong mang la: ');
for i:=1 to dem1 do
write(b[dem1]:4);
end;
writeln;
kt:=0;
for i:=1 to n do
if a[i] mod 2<>0 then kt:=1;
if kt=0 then writeln('Day la mang chan')
else writeln('Day khong la mang chan');
readln;
end.
Program hotrotinhoc;
var x,i,max,n: integer;
a,b: array[1..20] of integer;
begin
write('N='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
inc(b[a[i]]);
end;
max:=0;
for i:=1 to n do
if b[a[i]]>max then
begin
max:=b[a[i]];
x:=a[i];
end;
write('Phan tu co so lan xuat hien nhieu nhat trong mang la :',x);
readln
end.
#include <iostream> #include <algorithm> using namespace std; int main() { int a[] = { 5,5,5,5,5,4,4,4,4,3,3,3,2,2,1 }; int n = sizeof(a)/sizeof(a[0]); sort(a,a+n); int i = 0, max = 0,index = 0; int frequency; while(i < n) { frequency = 1; while(a[i] == a[i+1]) { frequency++; i++; } if(max < frequency) { max = frequency; index = i; } i++; } cout << "Maximum frequency: " << max << endl; cout << "Element has maximum frequency factor: " << a[index] << endl; return 0; }