Viết chương trình cho phép nhập số tự nhiên N từ bàn phím (với 0<n<=12) rồi thực hiện:
a: Tìm N! = 1.2.3...N
b: tìm S = \(\frac{1}{1!}+\frac{1}{2!}+\frac{1}{3!}+...+\frac{1}{N!}\)
c: T = \(1+\frac{2}{2^2}+\frac{3}{3^2}+\frac{4}{4^2}+...+\frac{1}{n^2}\)
d: S = \(1+\frac{1}{2^2}+\frac{1}{3^3}+\frac{1}{4^4}+...+\frac{1}{n^n}\)
e: \(S_n=\frac{1}{2}+\frac{2}{3}+\frac{3}{4}+\frac{4}{5}+...+\frac{n}{n+1}\)
f: S = \(1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+...+\frac{x^n}{n!}\)
b)
program hotrotinhoc;
var s: real;
i,n: byte;
function t(x: byte): longint;
var j: byte;
t1: longint;
begin
t1:=1;
for j:=1 to x do
t1:=t1*j;
t1:=t;
end;
begin
readln(n);
s:=0;
for i:=1 to n do
s:=s+1/t(i);
write(s:1:2);
readln
end.
c) Đề em ghi sai rồi thế này với đúng :
\(T=1+\frac{2}{2^2}+\frac{3}{3^2}+\frac{4}{4^2}+...+\frac{n}{n^2}\)
program hotrotinhoc;
var t: real;
n,i: byte;
begin
readln(n);
t:=0;
for i:=1 to n do
t:=t+i/(i*i);
write(t:1:2);
readln
end.
a)
uses crt;
var N,S,i : integer;
begin clrscr;
S:=1;
for i:= 1 to N do S:=S*i;
writeln('N!=',S);
readln
end.
Các cái kia tương tự :))
d)
program hotrotinhoc;
var i,n: byte;
s: real;
function mu(x: byte): longint;
var j : byte;
k: longint;
begin
k:=1;
for j:=1 to x do
k:=k*x;
k:=mu;
end;
begin
readln(n);
s:=0;
for i:=1 to n do
s:=s+1/mu(i);
write(s:1:2);
readln
end.
e)
program hotrotinhoc;
var s: real;
i,n: byte;
begin
readln(n);
s:=0;
for i:=1 to n do
s:=s+i/(i+1);
write(s:1:2);
readln
end.
f)
program hotrotinhoc;
var s: real;
i,n,x,j1: byte;
l: longint;
function t(x2: byte): longint;
var j: byte;
t1: longint;
begin
t1:=1;
for j:=1 to x2 do
t1:=t1*j;
t1:=t;
end;
begin
readln(n);
readln(x);
s:=1+x;
for i:=2 to n do
begin
for j1:=1 to i do l:=l*x;
s:=s+l/t(i);
end;
write(s:1:2);
readln
end.
a)
uses crt;
var n,i:integer;
gt:int64;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<=12) then
begin
gt:=1;
for i:=1 to n do
gt:=gt*i;
writeln(n,'!=',gt);
end
else writeln('ban vui long nhap lai');
readln;
end.
b)
uses crt;
var n,i,j:integer;
s:real;
gt:int64;
{--------------------------chuong-trinh-chinh---------------------------}
begin
clrscr;
write('n='); readln(n);
if (n>0) and (n<=12) then
begin
s:=0;
for i:=1 to n do
begin
gt:=1;
for j:=1 to i do
gt:=gt*j;
s:=s+1/gt;
end;
writeln('tong la: ',s:4:2);
end
else writeln('vui long nhap lai');
readln;
end.
c)
uses crt;
var n,i:integer;
t:real;
begin
clrscr;
write('nhap n='); readln(n);
if (n>0) and (n<=12) then
begin
t:=0;
for i:=1 to n do
t:=t+i/sqr(i);
writeln('tong la: ',t);
end
else writeln('vui long nhap lai');
readln;
end.
d)
uses crt;
var n,i,j:integer;
s:real;
k:int64;
begin
clrscr;
write('n='); readln(n);
if (n>0) and (n<=12) then
begin
s:=0;
for i:=1 to n do
begin
k:=1;
for j:=1 to i do
k:=k*i;
s:=s+1/k;
end;
writeln(s:4:2);
end
else writeln('vui long nhap lai');
readln;
end.
e)
uses crt;
var n,i:integer;
s:real;
begin
clrscr;
write('n='); readln(n);
if (n>0) and (n<=12) then
begin
s:=0;
for i:=1 to n do
s:=s+(i/(i+1));
writeln('Sn=',s:4:2);
end
else writeln('vui long nhap lai');
readln;
end.
f)
uses crt;
var n,x,j1,i,j:integer;
s:real;
lt,t1:int64;
begin
clrscr;
write('n='); readln(n);
write('x='); readln(x);
if (n>0) and (n<=12) then
begin
s:=1+x;
for i:=2 to n do
begin
lt:=1;
for j1:=1 to i do
lt:=lt*x;
t1:=1;
for j:=1 to i do
t1:=t1*j;
s:=s+lt/t1;
end;
writeln(s:4:2);
end
else writeln('vui long nhap lai');
readln;
end.