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.
Program HOC24;
var i,n: integer;
a: array[1..1000] of integer;
t: longint;
f1,f2: text;
const fi='DATA1.TXT';
fo='KQ1.TXT';
begin
assign(f1,fi);
assign(f2,fo);
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do read(f1,a[i]);
t:=0;
for i:=1 to n do if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
for i:=1 to n do if a[i] mod 5=0 then write(f2,a[i],' ');
close(f1); close(f2);
end.
tham khảo
Program Hotboy;
Uses crt;
Var A:array[1..100] of integer;
I,n : byte;
S:real;
Begin
Clrscr ;
S:=1;
Write('nhao so phan tu trong day'); readln(n);
For i:=1 to n do
Begin
Write('A[',i,']'); readln(A[i]);
End;
For i:=1 to n do
If A[i] mod 5 =0 then
S:=S* A[i] ;
Writeln('Tong cac phan tu chia het cho 5 trong mang la',S);
Readln
End.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
t:=1;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t*a[i];
writeln(t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t,j,tam:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:5);
writeln;
writeln('Cac so duong la: ');
for i:=1 to n do if (a[i]>0) then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln(t);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do write(a[i]:4);
readln;
end.
uses crt;
var a:array[1..100]of integer;
n,dem,i,j:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
begin
dem:=0;
for j:=1 to a[i] do
if a[i] mod j=0 then inc(dem);
if dem mod 2=0 then write('0 ')
else write('1 ');
end;
readln;
end.
Bài 2:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,ln,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
ln=a[1];
nn=a[1];
for (i=2; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<ln<<" "<<nn;
}
Bạn sài Quy hoạch động đi
c++:
#include <iostream>
#include <vector>
using namespace std;
const int N = (int) 1e5 + 5;
const int MOD = (int) 1e9;
int a[N];
int n;
int main() {
cin >> n;
if (n == 0) {
cout << 0 << endl;
return 0;
}
vector<int> p;
for (int i = 1;;) {
p.push_back(i * (3 * i - 1) / 2);
if (p.back() >= n) break;
i = -i;
if (i > 0) i++;
}
a[0] = 1;
for (int i = 1; i <= n; ++i) {
int sign = 1, cnt = 0;
for (int j : p) {
if (j > i) break;
a[i] += sign * a[i - j];
if (a[i] < 0) a[i] += MOD;
if (a[i] >= MOD) a[i] -= MOD;
cnt += 1;
if (cnt == 2) {
cnt = 0;
sign = -sign;
}
}
}
cout << a[n] << endl;
return 0;
}