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.

uses crt;

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

i,n,dem,t,t1,t2,t3,t4:integer;

begin

clrscr;

repeat

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

until (0<n) and (n<=250);

for i:=1 to n do 

  begin

repeat

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

until (0<a[i]) and (a[i]<=500);

end;

dem:=0;

for i:=1 to n do 

  if a[i] mod 2=1 then inc(dem);

writeln('So phan tu co gia tri le la: ',dem);

t:=0;

for i:=1 to n do 

  if i mod 2=0 then t:=t+a[i];

writeln('Tong cac phan tu co chi so chan la: ',t);

t1:=0;

for i:=1 to n do 

  if i mod 2=1 then t1:=t1+a[i];

writeln('Tong cac phan tu co chi so le la: ',t1);

t2:=0;

for i:=1 to n do 

  if (i mod 2=0) and (a[i] mod 2=0) then t2:=t2+a[i];

writeln('Tong cac phan tu chan co chi so chan la: ',t2);

t3:=0;

for i:=1 to n do 

  if (i mod 2=1) and (a[i] mod 2=1) then t3:=t3+a[i];

writeln('Tong cac phan tu co chi so le la: ',t3);

t4:=0;

for i:=1 to n do 

  t4:=t4+a[i];

writeln('Trung binh cong cac so trong day la: ',t4/n:4:2);

readln;

end.

#include <bits/stdc++.h>

using namespace std;

long long a[1000],n,i;

int main()

{

cin>>n;

for (i=1; i<=n; i++)

cin>>a[i];

for (i=1; i<=n; i++)

if (a[i]==0) 

{cout<<i; break; }

return 0;

}

1 tháng 12 2021

Tham khảo

 

B1: Nhập N, dãy số nguyên A, số nguyên k

B2: dem←0; i←1;

B3: Nếu i>N thì chuyển đến B6.

B4: Nếu A[i]>k thì dem←dem+1

B5: i←i+1; Quay lại B3.

B6: In dem ra màn hình và kết thúc.

16 tháng 4 2023

program BaiToanMang;

var
  A: array[1..100] of integer;
  N, i, demChan, tongLeChia3: integer;

begin
  write('Nhap so phan tu cua mang: ');
  readln(N);
  writeln('Nhap cac phan tu cua mang: ');
  for i := 1 to N do
  begin
    write('a[', i, ']= ');
    readln(A[i]);
  end;
  tongLeChia3 := 0;
  for i := 1 to N do
  begin
    if (A[i] mod 2 = 1) and (A[i] mod 3 = 0) then
    begin
      tongLeChia3 := tongLeChia3 + A[i];
    end;
  end;
  writeln('Tong cac so le chia het cho 3: ', tongLeChia3);
  demChan := 0;
  for i := 2 to N do
  begin
    if (A[i] mod 2 = 0) and (i mod 2 = 1) then
    begin
      demChan := demChan + 1;
    end;
  end;
  writeln('So phan tu chan o vi tri le: ', demChan);
  writeln('Cac so chan chia het cho 5: ');
  for i := 1 to N do
  begin
    if (A[i] mod 2 = 0) and (A[i] mod 5 = 0) then
    begin
      write(A[i], ' ');
    end;
  end;
end.

ko bt đúng ko ko dùng pascal nhiều

16 tháng 4 2023

b dùng pascal hay python V:

6 tháng 10 2023

#include <iostream>

#include <vector>

using namespace std;

bool divideArray(vector<int>& nums, int N) {

     int totalSum = 0;

     for (int i = 0; i < N; i++) {

          totalSum += nums[i];

     }

     if (totalSum % 2 != 0) {

          return false;

     }

     int halfSum = totalSum / 2;

     vector<vector<bool>> dp(N + 1, vector<bool>(halfSum + 1, false));

     dp[0][0] = true;

     for (int i = 1; i <= N; i++) {

          for (int j = 0; j <= halfSum; j++) {

               dp[i][j] = dp[i - 1][j];

               if (j >= nums[i - 1]) {

                    dp[i][j] = dp[i][j] || dp[i - 1][j - nums[i - 1]];

               }

          }

     }

     return dp[N][halfSum];

}

int main() {

     int N;

     cout << "Nhập số phần tử N: ";

     cin >> N;

     vector<int> nums(N);

     cout << "Nhập các phần tử của mảng: ";

     for (int i = 0; i < N; i++) {

          cin >> nums[i];

     }

     bool isPossible = divideArray(nums, N);

     if (isPossible) {

          cout << "Có thể chia mảng thành hai đoạn có tổng bằng nhau." << endl;

     } else {

          cout << "Không thể chia mảng thành hai đoạn có tổng bằng nhau." << endl;

     }

     return 0;

}

const fi='divk.inp';

fo='divk.out';

var f1,f2:text;

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

i,n,k,dem,j,x,t:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,n,k);

for i:=1 to n do 

  read(f1,a[i]);

dem:=0;

for i:=1 to n do 

  for j:=1 to n do 

begin

if i<j then 

begin

t:=0;

for x:=i to j do 

  t:=t+a[x];

if t=k then inc(dem);

end;

for i:=1 to n do 

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

writeln(f2,dem);

close(f1);

close(f2);

end.

15 tháng 10 2022

#include <bits/stdc++.h>
using namespace std;
#define nhungcute ios_base::sync_with_stdio; cin.tie(0); cout.tie(0);
const int N=1500;
long long n,k,a[N],i,j,c[N][101];
int main(){
nhungcute
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++){
        a[i]=a[i]%k;
    }
    for(i=1;i<k;i++)
    c[1][i] =-1e9;
    c[1][a[0]]=0;
    c[1][a[1]]=1;
    for(i=2;i<=n;i++){
        for(j=0;j<k;j++){
        c[i][j]=max(c[i-1][j],c[i-1][(j-a[i]+k)%k]+1);
        }
    }
    cout<<c[n][0];
    return 0;
}