Bạn chưa đăng nhập. Vui lòng đăng nhập để hỏi bài

Những câu hỏi liên quan
MINH NGỌC
Xem chi tiết
Phía sau một cô gái
11 tháng 3 2023 lúc 15:53

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.

Tiện Tiện
Xem chi tiết
nguyễn an phát
24 tháng 5 2021 lúc 11:06

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.

Lala
Xem chi tiết
Trương Huy Hoàng
13 tháng 12 2023 lúc 22:58

#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!

HOÀNG ĐẠI PHÚC
Xem chi tiết
No_sun
Xem chi tiết
Gia Huy
26 tháng 6 2023 lúc 15:29

```
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].)

Nguyễn Hoàng Duy
27 tháng 6 2023 lúc 10:03

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == x){
            count++;
        }
    }
    cout << count << endl;
}

 

Đặng Nguyễn Hoài Băng
Xem chi tiết

#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;
}

 

 

Nguyen Bảo Nhi
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 4 2021 lúc 20:14

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. 

Nguyễn Trần Cảnh Nam
8 tháng 4 2021 lúc 22:07

bằng c++ hay pascal?

 

Hiểu Nguyễn Đức
Xem chi tiết
Nguyễn Lê Phước Thịnh
19 tháng 5 2022 lúc 14:17

#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;

}

Hiểu Nguyễn Đức
Xem chi tiết
Nguyễn Lê Phước Thịnh
19 tháng 5 2022 lúc 14:17

#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;

}

Kudo Shinichi
25 tháng 5 2022 lúc 19:31

#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;

}