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,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x>0) t+=x;
}
cout<<t;
return 0;
}
Bạn tham khảo link :https://hoc247.net/hoi-dap/tin-hoc-11/viet-chuong-trinh-lap-mang-a-gom-n-so-nguyen-faq299502.html
uses crt;
var a:array[1..100]of integer;
i,n,kt,dem,j:integer;
begin
clrscr;
write('Nhap n='); readln(n);
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]>1 then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then
begin
kt:=1;
break;
end;
if kt=0 then inc(dem);
end;
writeln('So phan tu la so nguyen to la: ',dem);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem,t:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=1000);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until abs(a[i])<=1000;
end;
for i:=1 to n do
write(a[i]:4);
writeln;
dem:=0;
for i:=1 to n do
if a[i]=0 then inc(dem);
writeln('So phan tu bang 0 la: ',dem);
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('Tong cac phan tu chan la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[100],i,n,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
sort(a+1,a+n+1);
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++) t+=a[i];
cout<<t;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,t,k:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
readln(k);
t:=0;
for i:=1 to n do
if a[i] mod k=0 then t:=t+a[i];
writeln(t);
readln;
end.
Uses crt;
Var A: array[1..100] of longint;
n,k,i,s: longint;
Begin
Clrscr;
Write(‘Nhap n,k: ‘); Readln(n,k);
s:=0;
For i:=1 to n do
Begin
Read(A[i]);
If A[i] mod k = 0 then s:=s+A[i];
End;
Write(s);
Readln
End.
ai đó giúp mình gấp với