K
Khách

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.

11 tháng 3 2023

program dem_so_lan_xuat_hien;

uses crt;

var

     A: array[1..100] of integer;

     N, X, i, count: integer;

begin

     clrscr;

     write('Nhap so phan tu mang A: '); readln(N);

     for i := 1 to N do

     begin

          write('A[',i,'] = ');

          readln(A[i]);

     end;

     write('Nhap gia tri can tim x: '); readln(X);

     count := 0;

      for i := 1 to N do

     begin

          if A[i] = X then

               count := count + 1;

     end;

     writeln('So lan xuat hien cua ', X, ' trong mang A la: ', count);

     readln;

end.

24 tháng 5 2021

program tinh_so_lan_xuat_hien;

uses crt;

var i,n,x,d:integer;

a:array[1..100]of integer;

begin

clrscr;

write('nhap n:');readln(n);

for i:=1 to n do

begin

write('a[',i,']=');readln(a[i]);

end;

d:=0;

write('nhap x:');readln(x);

for i:=1 to n do

if x=a[i] then inc(d);

writeln(x,' xuat hien ',d,' lan trong mang a');

readln;

end.

13 tháng 12 2023

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("MAP1.INP","r",stdin);
    freopen("MAP1.OUT","w",stdout);
    ll n; cin >> n;
    ll a[n+5];
    for(ll i=1;i<=n;i++) cin >> a[i], mp[a[i]]++;
    for(pair<ll,ll> it:mp) cout << it.first << " " << it.second << "\n";
}

Chúc bạn học tốt!

26 tháng 6 2023

```
n, k = map(int, input().split())
a = list(map(int, input().split()))

count = 0
for i in range(n):
if a[i] == k:
count += 1

print(count)
```

giải thích: dòng đầu đọc vào số n và giá trị k, dòng hai đọc vào mảng a. Biến count được khởi tạo bằng 0 để đếm số lần xuất hiện của giá trị k trong mảng a. Vòng lặp for duyệt qua từng phần tử trong mảng a. Nếu phần tử đó bằng k => tăng biến count lên 1. Sau cùng, in ra giá trị của biến count.

Ví dụ:

Input:
```
5 2
1 2 3 2 4
```

Output:
```
2
```

(Giá trị 2 xuất hiện 2 lần trong mảng [1, 2, 3, 2, 4].)

26 tháng 6 2023

bn có thể lm c++ dc ko

đầu vào #include<bits/stdc++.h>

 

#include <bits/stdc++.h>
using namespace std;
int n,x,i,cnt,res=0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>x;
for(i=0;i<n;i++)
{
    cin>>cnt;
    if(cnt==x) res++;
}
cout<<"so luong xuat hien so "<<x<<" la: "<<res;
return 0;
}

 

 

uses crt;

var a:array[1..100]of integer;

i,n,k,h,dem,t,dem1,dem2,t1,t2:integer;

begin

clrscr;

for i:=1 to 100 do 

  begin

write('A[',i,']='); readln(a[i]);

end;

n:=100;

write('Nhap k='); readln(k);

for i:=1 to n do 

  if a[i]=k then write(i:4);

writeln;

write('Nhap h='); readln(h);

dem:=0;

for i:=1 to n do 

  if a[i]=h then inc(dem);

writeln(h,' xuat hien ',dem,' lan trong mang');

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln('Tong cac phan tu cua day la: ',t);

dem1:=0;

t1:=0;

dem2:=0;

t2:=0;

for i:=1 to n do 

  begin

if a[i]>0 then

begin

inc(dem1);

t1:=t1+a[i];

end;

if a[i]<0 then 

begin

inc(dem2);

t2:=t2+a[i];

end;

end;

writeln('Co ',dem1,' so duong');

writeln('Tong cac so duong la: ',t1);

writeln('Co ',dem2,' so am');

writeln('Tong cac so am la: ',t2);

readln;

end. 

8 tháng 4 2021

bằng c++ hay pascal?

 

4 tháng 5 2023

program tinh_tong_va_dem_so_x;

const
  MAX = 100;

var
  a: array[1..MAX] of integer;
  n, tong, x, dem, i: integer;

begin
  write('Nhap so phan tu cua mang: ');
  readln(n);
  for i := 1 to n do
  begin
    write('Nhap phan tu thu ', i, ': ');
    readln(a[i]);
  end;
  tong := 0;
  for i := 1 to n do
  begin
    tong := tong + a[i];
  end;
  writeln('Tong cac phan tu trong mang la: ', tong);
  write('Nhap gia tri x: ');
  readln(x);
  dem := 0;
  for i := 1 to n do
  begin
    if a[i] = x then
    begin
      dem := dem + 1;
    end;
  writeln('So lan xuat hien cua ', x, ' trong mang la: ', dem);
  readln;
end.