Viết chương trình nhập mảng A có N phần tử là số nguyên (N được nhập bất kì từ bàn phím). Hãy đếm xem có bao nhiêu phần tử dương.
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 a[1000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
uses crt;
var a:array[1..10]of longint;
n,i,t,dem,dem1,dem2,t1:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
t1:=0;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then dem1:=dem+1;
if a[i] mod 2=0 then
begin
dem2:=dem2+1;
t1:=t1+a[i];
end;
end;
writeln(dem1);
writeln(t1/dem2:4:2);
readln;
end.
uses crt;
var a:array[1..10]of longint;
n,i,t,dem,dem1,dem2,t1:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
t1:=0;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then dem1:=dem+1;
if a[i] mod 2=0 then
begin
dem2:=dem2+1;
t1:=t1+a[i];
end;
end;
writeln(dem1);
writeln(t1/dem2:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[100],n,i,t,t1,dem,dem1;
//chuongtrinhcon
bool ktnt(long long x)
{
if (x<=1) return(false);
for (int i=2; i*i<=x; i++)
if (x%i==0) return(false);
return true;
}
//chuongtrinhchinh
int main()
{
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i];
}
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++) if (a[i]%2==0) t=t+a[i];
cout<<t<<endl;
dem=0;
for (i=1; i<=n; i++) if (a[i]%3==0) dem++;
cout<<dem<<" ";
t1=0;
dem1=0;
for (i=1; i<=n; i++)
if (a[i]%2!=0)
{
t1+=a[i];
dem1++;
}
cout<<fixed<<setprecision(2)<<(t1*1.0)/(dem1*1.0)<<endl;
for (i=1; i<=n; i++)
if (ktnt(a[i])==true) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[100],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]==7) dem++;
cout<<dem;
return 0;
}
uses crt;
var a:array[1..100]of integer;
m,n,dem,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap m='); readln(m);
dem:=0;
for i:=1 to n do
if a[i]=m then inc(dem);
writeln('So phan tu bang ',m,' la: ',dem);
readln;
end.
#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;
}
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x>0) dem++;
}
cout<<dem;
return 0;
}