nhập vào mảng B . đếm số hạng âm ; dương và bằng 0 trong dãy
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..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.
uses crt;
var a,b:array[1..50]of integer;
i,n,dem,dem1,min:integer;
begin
clrscr;
n:=50;
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
dem1:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
b[dem1]:=a[i];
end;
min:=b[1];
for i:=1 to dem1 do
if min>b[i] then min:=b[i];
writeln('Phan tu am be nhat trong mang la: ',min);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t,dem: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
if a[i] mod 6=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 3 va 6 la: ',t);
for i:=1 to n do
if a[i]>3 then write(a[i]:4);
writeln;
for i:=1 to n do
write(a[i]:4);
dem:=0;
for i:=1 to n do
if (a[i] mod 2<>0) and (a[i] mod 5=0) then inc(dem);
writeln(dem);
readln;
end.
2:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
dem=0;
for (i=1; i<=n; i++)
if (a[i]%2==0 && a[i]<0) dem++;
cout<<dem;
return 0;
}
#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;
}
#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;
}
#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;
}
var a:array[1..1000] of integer;
i,n,d,max:integer;
begin
write('n = ');readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' = ');readln(a[i]);
if a[i] mod 2 <> 0 then d:=d+1;
end;
max:=a[1];
for i:=2 to n do
if a[i] > max then max:=a[i];
writeln('Co ',d,' so le');
write('So lon nhat la ',max);
readln
end.
program dem_so_am_duong_0;
uses crt;
var B: array[1..100] of integer;
i, n, count_am, count_duong, count_0: integer;
begin
write('Nhap n: ');
readln(n);
for i :=1 to n do
begin
write('Nhap phan tu B[' , i, ']: ');
readln(B[i]);
end;
count_am :=0;
count_duong :=0;
count_0 :=0;
for i :=1 to n do
begin
if B[i] < 0 then
count_am := count_am + 1
else if B[i] > 0 then
count_duong := count_duong + 1
else
count_0 := count_0 + 1;
end;
write('So phan tu am trong mang: ', count_am);
write('So phan tu duong trong mang: ', count_duong);
write('So phan tu bang 0 trong mang: ', count_0);
readln;
end.