Những câu hỏi liên quan
TRIẾT PHẠM
Xem chi tiết
Lê Phương Thảo
Xem chi tiết
Nguyễn Lê Phước Thịnh
25 tháng 2 2021 lúc 21:55

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.

Bình luận (0)
ngo minh duc
Xem chi tiết
Nguyễn Lê Phước Thịnh
21 tháng 3 2021 lúc 9:26

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.

Bình luận (0)
APOK FF
Xem chi tiết
Hoài Linh
Xem chi tiết
Nguyễn Lê Phước Thịnh
27 tháng 10 2021 lúc 15:14

a: #incldue <bits/stdc++.h>

using namespace std;

long long i,n,x,t;

int main()

{

cin>>n;

t=0;

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

{

cin>>x;

if (x>0) t=t+x;

}

cout<<t;

return 0;

}

Bình luận (0)
hioer
Xem chi tiết
Anh Thư
Xem chi tiết
Minh Lệ
10 tháng 4 2021 lúc 18:25

Program HOC24;

var d,i,n: integer;

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

t: longint;

function nt(x: longint): boolean;

var j: longint;

begin

nt:=true;

if (x=2) or (x=3) then exit;

nt:=false;

if (x=1) or (x mod 2=0) or (x mod 3=0) then exit;

j:=5;

while j<=trunc(sqrt(x)) do

begin

if (x mod j=0) or (x mod (j+2)=0) then exit;

j:=j+6;

end;

nt:=true;

end;

begin

write('Nhap N: '); readln(n);

for i:=1 to n do

begin

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

end;

d:=0; t:=0;

for i:=1 to n do

if nt(a[i]) then

begin

d:=d+1;

t:=t+a[i];

end;

writeln('Co ',d,' so nguyen to trong day');

write('Tong cac so nguyen to trong day la: ',t);

readln

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
10 tháng 4 2021 lúc 20:18

uses crt;

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

i,n,dem,t,j,kt:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

dem:=0;

t:=0;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt:=0;

for j:=2 to a[i]-1 do 

 if a[i] mod j=0 then kt:=1;

if kt=0 then

begin

inc(dem);

t:=t+a[i];

end;

end;

writeln('So luong so nguyen to la: ',dem);

writeln('Tong cac so nguyen to la: ',t);

readln;

end.

Bình luận (0)
Bế Sỹ Trịnh
Xem chi tiết
Nguyễn Lê Phước Thịnh
30 tháng 12 2021 lúc 15:41

#include <bits/stdc++.h>

using namespace std;

long long n,i,x,dem1,dem2;

int main()

{

cin>>n;

dem1=0;

dem2=0;

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

{

cin>>x;

if (x%2==0) dem1++;

else dem2++;

}

cout<<dem1<<" "<<dem2;

return 0;

}

Bình luận (0)
Tiếng anh123456
Xem chi tiết
Phía sau một cô gái
11 tháng 8 2023 lúc 21:32

#include <iostream>

#include <vector>

using namespace std;

pair<int, int> findMaxSubarray(vector<int> nums) {

     int n = nums.size();

     int maxSum = nums[0];

     int currentSum = nums[0];

     int start = 0;

     int end = 0;

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

          if (currentSum < 0) {

               currentSum = nums[i];

               start = i;

               end = i;

          } else {

               currentSum += nums[i];

               end = i;

          }

          if (currentSum > maxSum) {

               maxSum = currentSum;

          }

     }

     return make_pair(start, end);

}

int main() {

     int numTests;

     cin >> numTests;

     for (int t = 0; t < numTests; t++) {

          int n;

          cin >> n;

          vector<int> nums(n);

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

               cin >> nums[i];

          }

          pair<int, int> maxSubarray = findMaxSubarray(nums);

          cout << maxSubarray.first << " " << maxSubarray.second << endl;

     }

     return 0;

}

Bình luận (0)