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.
1: tính tổng của \(S=1+\frac{1}{2^2}+\frac{1}{3^2}+\frac{1}{4^2}+...+\frac{1}{100^2}\)
uses crt;
var s:real;
i:integer;
begin
clrscr;
s:=0;
for i:=1 to 100 do
s:=s+1/(sqr(i));
writeln('tong cua day so la: ',s);
readln;
end.
2: tính tổng \(S=1+\frac{1}{3^2}+\frac{1}{5^2}+\frac{1}{7^2}+...+\frac{1}{n^2}\)
uses crt;
var s:real;
n,i:integer;
begin
clrscr;
write('n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 2=1 then s:=s+1/(sqr(i));
writeln('tong cua day so la: ',s:4:2);
readln;
end.
uses crt;
var a:array[1..255]of byte;
n,i,kt:integer;
st,st1:string;
begin
clrscr;
write('nhap chieu dai day so:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------xu-ly---------------------------------}
st:='';
kt:=0;
for i:=1 to n do
if a[i] mod 2=1 then
begin
str(a[i],st1);
kt:=1;
st:=st+st1;
end;
if kt>0 then
begin
write('doi xung cua cac so le la: ');
for i:=1 to length(st) do
write(st[i]:4);
for i:=length(st) downto 1 do
write(st[i]:4);
end;
readln;
end.
uses crt;
var st,st1,st2:string;
a:array[1..255]of integer;
n,d,i,dem,x,kt:integer;
begin
clrscr;
write('nhap so n:'); readln(n);
str(n,st);
d:=length(st);
for i:=1 to d do
val(st[i],a[i],x);
st2:='';
dem:=0;
kt:=0;
for i:=1 to d do
if a[i] mod 2<>0 then
begin
kt:=1;
dem:=dem+1;
str(a[i],st1);
st2:=st2+st1;
end;
if kt>0 then
begin
write('doi xung cua phan con lai sau khi xoa bot cac so chan la: ');
for i:=1 to dem do
write(st2[i]);
for i:=dem downto 1 do
write(st2[i]);
end;
readln;
end.
Bài 1:
Program hotrotinhoc;
var a,b,c,d,max: integer;
begin
write('Nhap a,b,c,d :'); readln(a,b,c,d);
max:=0;
if a>max then max:=a;
if b>max then max:=b;
if c>max then max:=c;
if d>max then max:=d;
write(max);
readln
end.
Bài 2:
Program hotrotinhoc;
var a,b,c : integer;
begin
write('Nhap 3 canh a,b,c'); readln(a,b,c);
if (a+b>c) or (a+c>b) or (b+c>a) then write('Thoa man') else ('Khong thoa man trong tung truong hop tuong ung');
readln
end.
Bài 4: Câu hỏi của Quỳnh Như - Tin học 8 | Học trực tuyến
Bài 5:
Program hotrotinhoc;
var a,n: integer;
t: longint;
begin
Write('Nhap a,n :'); readln(a,n);
t:=1;
for i:=1 to n do
t:=t*a;
write(t);
readln
end.
Bài 1:
program pstg;
uses crt;
var a,b,i,u : integer;
f : text;
BEGIN
clrscr;
assign(f,'PSTG.INP');
reset(f);
read(f, a);
read(f, b);
u:=1;
for i:= 1 to a do if ((a mod i)=0) and ((b mod i)=0) and (i>u) then u:=i;
a:= a div u;
b:= b div u;
assign(f,'PSTG.OUT');
rewrite(f);
write(f, a,' ',b);
close(f);
END.
bài 4 dễ ẹt à
uses crt;
const fi='quediem.inp';
fo='quediem.out';
var i,m,n,d,x,j,csc:longint;
a,b:array[1..1000]of integer;
f1,f2:text;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
{-------------------------tim-so-lon-nhat--------------------------}
write(f2,'so lon nhat la: ');
m:=n;
if m mod 2=0 then
begin
for i:=1 to n div 2 do
write(f2,'1');
end
else begin
write(f2,'7');
for i:=2 to n div 2 do
write(f2,'1');
end;
{----------------------------tim-so-nho-nhat------------------------}
writeln(f2);
a[1]:=2; b[1]:=1;
a[2]:=5; b[2]:=2;
a[3]:=4; b[3]:=4;
a[4]:=6; b[4]:=6;
a[5]:=3; b[5]:=7;
a[6]:=7; b[6]:=8;
d:=(n div 7)+1;
if n mod 7=0 then d:=d-1;
if d=1 then begin
case n of
2:write(f2,'so nho nhat la: ',1);
3:write(f2,'so nho nhat la: ',7);
4:write(f2,'so nho nhat la: ',4);
5:write(f2,'so nho nhat la: ',2);
6:write(f2,'so nho nhat la: ',0);
7:write(f2,'so nho nhat la: ',8);
end;
end;
if d>1 then
begin
write(f2,'so nho nhat la: ');
for i:=1 to d do
if i=1 then begin
b[4]:=6;
for j:=1 to 6 do
begin
x:=n;
x:=x-a[j];
csc:=x div 7+1;
if x mod 7=0 then csc:=csc-1;
if csc=d-i then begin
write(f2,b[j]);
n:=x;
break;
end;
end;
end
else begin
a[1]:=6; b[1]:=0;
a[2]:=2; b[2]:=1;
a[3]:=5; b[3]:=2;
a[4]:=4; b[4]:=4;
a[5]:=3; b[5]:=7;
a[6]:=7; b[6]:=8;
for j:=1 to 6 do
begin
x:=n;
x:=x-a[j];
csc:=(x div 7)+1;
if x mod 7=0 then csc:=csc-1;
if csc=d-i then begin
write(f2,b[j]);
n:=x;
break;
end;
end;
end;
end;
close(f1);
close(f2);
readln;
end.
Program hotrotinhoc_hoc24;
const fi='C:\Input.txt';
fo='C:\Output.txt';
var f: text;
i,n: integer;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,n);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
for i:=1 to n do write(f,i,' ');
close(f);
end;
begin
ip;
out;
end.
const fi='input.txt';
fo='output.txt';
var f1,f2:text;
i,n:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
write(f2,i:4);
close(f1);
close(f2);
end.
Lời giải:
program hotrotinhoc;
var a,b : integer;
s: longint;
t: real;
begin
write('A='); readln(a);
write('B='); readln(b);
s:=a;
s:=s+b;
writeln(s);
s:=0;
s:=a;
s:=s-b;
writeln(s);
s:=0;
s:=a;
s:=s*b;
writeln(s);
t:=a;
t:=t/b;
write(t:1:2);
readln
end.
Bài làm của bạn @lê chí hiếu(bạn được 2,1 điểm)
bài 1
program PTYN;
uses crt;
var a:array[1..100,1..100]of integer;
i,j,m,n:integer;
f1,f2:text;
Max, Min:Integer;
Kt:boolean;
Procedure XuatMang;
begin
For i:=1 to n do
begin
for j:=1 to m do
Write(a[i,j]:4);
Writeln;
end;
end;
Procedure MaxCot(l:Integer);
var p:Integer;
begin
Max:=A[1,l];
For p:=2 to n do
if A[p,l]>Max then Max:=A[p,l];
end;
Procedure MinHang(k:Integer);
var o:integer;
begin
Min:=A[k,1];
For o:=2 to n do
if A[k,o]<Min then Min:=A[k,o];
end;
begin
clrscr;
assign(f1,'ptyn.inp');
assign(f2,'ptyn.out');
reset(f1);rewrite(f2);
while not EOF(f1) do
begin
kt:=false;
readln(f1,n,m);
for i:=1 to n do
begin
for j:=1 to m do
Read(f1,a[i,j]);
readln(f1);
end;
for i:=1 to n do
begin
for j:=1 to n do
begin
MaxCot(j);
MinHang(i);
if Max=Min then
begin
Writeln(f2,'(',i,',',j,')');
kt:=true;
end;
end;
end;
If kt=false then Writeln(f2,'Khong co ptu yen ngua.');
end;
Close(f1); Close(f2);
Readln
End.
Bài 4
const fi='tvh.inp';
fo='tvh.out';
var n,d,dem,sl,s2cs,s3cs,s4cs,s5cs,s6cs,s7cs,k,i,d1:longint;
st,st1,stk:string;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,k);
str(n,st);
d:=length(st);
case d of
1: write(9);
2: begin
sl:=n-9;
dem:=9+sl*2;
end;
3: begin
s2cs:=(99-10)+1;
s3cs:=n-99;
dem:=9+s2cs*2+s3cs*3;
end;
4: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=n-999;
dem:=9+s2cs*2+s3cs*3+s4cs*4;
end;
5: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=n-9999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5;
end;
6: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=n-99999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6;
end;
7: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=(999999-1000000)+1;
s7cs:=n-999999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6+s7cs*7;
end;
end;
if k<=dem then
begin
i:=1;
d1:=0;
repeat
str(i,st1);
d1:=d1+length(st1);
i:=i+1;
until d1>=k;
stk:=st1[length(st1)-(d1-k)];
writeln(f2,stk);
end;
close(f1);
close(f2);
end.
Bài 5
PROGRAM robot;
VAR A:ARRAY[0..30,0..30] OF BYTE;
F:ARRAY[0..30,0..30] OF LONGINT;
m,n:INTEGER;
PROCEDURE Enter;
VAR i,j:INTEGER;
BEGIN
readln(m,n);
FOR i:=1 TO m DO
BEGIN
FOR j:=1 TO n DO read(A[i,j]);
readln;
END;
FOR i:=0 TO m DO A[i,0]:=-1;
FOR j:=0 TO n DO A[0,j]:=-1;
END;
FUNCTION Max(a,b:LONGINT):LONGINT;
BEGINIF (a>b) THEN Max:=a ELSE Max:=b;
END;
PROCEDURE Optimize;
VAR i,j:INTEGER;
BEGIN
FOR i:=0 TO m DO F[i,0]:=-1;
FOR j:=0 TO n DO F[0,j]:=-1;
F[0,1]:=0;
FOR i:=1 TO m DO
FOR j:=1 TO n DO
F[i,j]:=2*Max(F[i,j-1],F[i-1,j])+A[i,j];
END;
PROCEDURE Trace(i,j:INTEGER);
BEGINIF (i=1) AND (j=1) THEN
writeln(F[m,n])
ELSE
BEGIN
IF F[i,j-1]>F[i-1,j] THEN
Trace(i,j-1)
ELSE
Trace(i-1,j);
writeln(i,' ',j);
END;
END;
BEGIN
Assign(Input,'Robot.inp'); Reset(Input);
Assign(Output,'Robot.out');Rewrite(Output);
Enter;
Optimize;
Trace(m,n);
close(Input);
close(Output);
END.
Em hiểu,nhưng cách anh chỉ đến 8 chữ số là cùng.
Cách em thì chỉ cần lấy int64(em dùng luôn mấy biến real vì bự hơn) thì chấp 10^30
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;
}