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.
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,dem1,dem2,t1,t2;
int main()
{
cin>>n;
dem1=0;
dem2=0;
t1=0;
t2=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x>0)
{
dem1++;
t1+=x;
}
if (x<0)
{
dem2++;
t2+=x;
}
}
cout<<dem1<<" "<<dem2<<endl;
cout<<t1<<" "<<t2;
return 0;
}
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à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;
}
uses crt;
var a:array[1..100]of integer;
i,n,t,t1,t2:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
t1:=0;
t2:=0;
for i:=1 to n do
begin
if a[i]>0 then t1:=t1+a[i];
if a[i]<0 then t2:=t2+a[i];
end;
writeln('Tong cac phan tu la: ',t);
writeln('Tong cac so duong la: ',t1);
writeln('Tong cac so am la: ',t2);
writeln('Trung binh cong cua day la: ',t/n:4:2);
readln;
end.
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.
#include <bits/stdc++.h>
using namespace std;
double a[100],t1,t2,k;
int i,n,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
cin>>k;
dem=0;
for (i=1; i<=n; i++) if (a[i]==k) dem++;
t1=0;
t2=0;
for (i=1; i<=n; i++)
{
if (a[i]>0) t1+=a[i];
else t2+=a[i];
}
cout<<dem<<endll;
cout<<t1<<" "<<t2;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem,s,s1,vt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
s:=1;
for i:=1 to n do
if a[i]=3 then
begin
inc(dem);
s:=s*a[i];
end;
writeln('So phan tu bang 3 la: ',dem);
writeln('Tich cua chung la: ',s);
for i:=n downto 1 do
if a[i]<0 then
begin
vt:=i;
break;
end;
if vt=0 then writeln('Trong day khong co so am')
else writeln('So am cuoi cung la: ',a[vt]);
s1:=1;
for i:=1 to n do
if (a[i] mod 3=0) or (a[i] mod 4=0) then s1:=s1*a[i];
writeln('Tich cac phan tu chia het cho 3 hoac 4 la: ',s1);
writeln('Cac so nguyen la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x<0) t+=x;
}
cout<<t;
return 0;
}
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;
}