Cho dãy số nguyên A gồm N phần tử (N
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.
#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> count;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
count[x]++;
}
int ans = 0;
for (auto p : count) {
int x = p.second;
ans += (x * (x - 1)) / 2;
}
cout << ans;
return 0;
}
uses crt;
var a:array[1..300]of integer;
i,n,t,tb: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 i mod 2=1 then t:=t+a[i];
tb:=0;
for i:=1 to n do
tb:=tb+a[i];
writeln('Tong cac phan tu cua day o vi tri le la: ',t);
writeln('Trung binh cong cua day la: ',tb/n:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
int main()
{
freopen("dayd.inp","r",stdin);
freopen("dayd.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]>0) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n,t;
int main()
{
freopen("avg.inp","r",stdin);
freopen("avg.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++) t+=a[i];
cout<<fixed<<setprecision(1)<<(t*1.0)/(n*1.0);
return 0;
}
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,min:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln(min);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n,max:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln(max);
readln;
end.
Câu 7:
const fi='dayso.inp';
fo='dayso.out';
var f1,f2:text;
a,b:array[1..100]of integer;
i,n,dem,j,t,kt,dem1:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,'Tong cua day so la: ',t);
b[1]:=a[1];
dem:=1;
for i:=1 to n do
begin
kt:=0;
for j:=1 to dem do
if a[i]=b[j] then kt:=1;
if kt=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
end;
for i:=1 to dem do
begin
dem1:=0;
for j:=1 to n do
if b[i]=a[j] then inc(dem1);
writeln(f2,b[i],' xuat hien ',dem1,' lan');
close(f1);
close(f2);
end.
Câu 1:
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
t:=t+a[i];
writeln(t);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,x,dem,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap x='); readln(x);
kt:=0;
dem:=0;
for i:=1 to n do
if a[i]=x then
begin
kt:=1;
write(i:4);
inc(dem);
end;
if kt=0 then writeln('Khong co ',x,' trong day');
writeln(x,' xuat hien ',dem,' lan trong day');
readln;
end.
Bạn bổ sung đề nhé