Những câu hỏi liên quan
Bui Trong Diep
Xem chi tiết
Nguyễn Lê Phước Thịnh
11 tháng 5 2022 lúc 18:51

uses crt;

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

i,n,dem1,dem2,t1,t2,sa,sd,vt1,vt2:integer;

begin

clrscr;

readln(n);

for i:=1 to n do readln(a[i]);

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(dem1);

writeln(dem2);

writeln(t1);

writeln(t2);

for i:=1 to n do 

  if a[i]>0 then 

begin

sd:=a[i];

vt1:=i;

break;

end;

if (dem1=0) then writeln('Khong co so duong trong day')

else writeln('So duong dau tien la: ',sd,' vi tri la: ',vt1);

for i:=1 to n do 

  if a[i]<0 then 

begin

sa:=a[i];

vt2:=i;

break;

end;

if (dem2=0) then writeln('Khong co so am trong day')

else writeln('So am dau tien la: ',sa,' vi tri la: ',vt2);

readln;

end.

Bình luận (0)
Anh Lê duy
Xem chi tiết
Danh Nguyễn
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 3 2022 lúc 7:23

Bài 1:

#include <bits/stdc++.h>

using namespace std;

long long x,n,i,t;

int main()

{

cin>>n;

t=0;

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

{

cin>>x;

if ((x<0) and (x%2!=0)) t=t+x;

}

cout<<t;

return 0;

}

Bình luận (0)
hihi
Xem chi tiết
Nguyễn Lê Phước Thịnh
25 tháng 2 2021 lúc 22:05

uses crt;

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

i,n,dem,dem1,dem2,t:integer;

begin

clrscr;

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

for i:=1 to n do 

begin

write('B[',i,']='); readln(b[i]);

end;

dem:=0;

dem1:=0;

for i:=1 to n do 

begin

if b[i]<0 then inc(dem);

if b[i]>0 then inc(dem1);

end;

writeln('So phan tu am la: ',dem);

writeln('So phan tu duong la: ',dem1);

t:=0;

for i:=1 to n do 

 if b[i]<>0 then t:=t+b[i];

writeln('Trung binh cac phan tu khac 0 trong mang la: ',t/(dem+dem1):4:2);

min:=b[1];

for i:=1 to n do

  if min>b[i] then min:=b[i];

dem2:=0;

for i:=1 to n do 

  if min=b[i] then

begin

 inc(dem2);

a[dem2]:=i;

end;

writeln('Gia tri nho nhat la: ',min);

writeln('Chi so la: ');

for i:=1 to dem2 do 

  write(a[i]:4);

readln;

end.

Bình luận (1)
nông thị ngân
Xem chi tiết
Nguyễn Lê Phước Thịnh
22 tháng 3 2021 lúc 19:41

uses crt;

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

n,i,k,t,t1:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

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

t:=0;

for i:=1 to n do 

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

t1:=0;

for i:=1 to n do 

  if a[i] mod k=0 then t1:=t1+a[i];

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

writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);

readln;

end.

Bình luận (1)
Tuyên Dương
Xem chi tiết
Trâm Đỗ
Xem chi tiết
Nguyễn Lê Phước Thịnh
7 tháng 12 2021 lúc 23:07

1:

#include <bits/stdc++.h>

using namespace std;

long long t1,t2,i,n,x;

int main()

{

cin>>n;

t1=0;

t2=0;

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

{

cin>>x;

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

else t2=t2+x;

}

cout<<t1<<" "<<t2;

return 0;

}

Bình luận (0)
an1114
Xem chi tiết
Trần Cương
Xem chi tiết
Ngô Thành Chung
22 tháng 3 2022 lúc 22:07

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

      i,n,S,d:byte;

 begin

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

  for i:=1 to n do begin

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

                           readln(A[i]);

                          end;

d:=0; S:=0;

for i:=1 to n do if A[i] mod 2 = 0 then begin

                                                          d:=d+1;

                                                           S:=S+A[i];

                                                           end;

write('Dãy có ',d,' phần tử là số chẵn và tổng của chúng là : S = ',S);

readln

end.

                                                          

                      

  

Bình luận (0)