viết chương trình tính tổng ;s=1/2+1/3+1/5+1/7...+1/(2n+1)(n thuộc N)(với số n nhập từ bàn phím)
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.
Var i ,n : integer;
S , T : real;
Begin
Write ('n:') ;
Read (n) ;
S:= 0;
T:= 1;
For i:= 1 to n do
S:= S + i;
T:= T * i;
Writeln (' Tong cua ' ,n,' , S );
Writeln (' Tich của ' ,n,', T );
Readln;
End.
2.
program SumAndProductOfNumbers;
var
n, m, i, sum, product: integer;
begin
writeln('Enter the values of n and m: ');
readln(n, m);
sum := 0;
product := 1;
for i := n to m do
begin
sum := sum + i;
product := product * i;
end;
writeln('The sum of numbers from ', n, ' to ', m, ' is: ', sum);
writeln('The product of numbers from ', n, ' to ', m, ' is: ', product);
end.
Câu 6:
uses crt;
var n,i:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.
5:
uses crt;
var n,i,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
for i:=0 to n do
if i mod 2=1 then
begin
write(i:4);
dem:=dem+1;
end;
writeln;
writeln(dem);
readln;
end.
Câu 1:
var i,n:integer;
s:longint;
begin
write('Nhap n = ');readln(n);
for i:=1 to n do
s:=s+(i*10+2);
write('S = ',s);
readln;
end.
Câu 2:
var i,n:integer;
s:real;
begin
write('Nhap n = ');readln(n);
for i:=1 to n do s:=s+1/n;
write('tong la ',s:10:2);
readln;
end.
Câu 1:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cac so trong mang la: ',t);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('Tong cac so chan la: ',t);
readln;
end.
For...do:
var s,i: integer;
begin
readln(s,i);
s:=0;
For i:=3 to 99 do
If i mod 3 = 0 do s:=s+i;
write(s)
readln;
end.
while ... do:
Var i,S:integer;
Begin
Readln(i,s);
S:=0;
i:=3;
while i<=99 do
if i mod 3 = 0 then s:=s+i;
write(s);
Readln;
End.
Vd:
#include <bits/stdc++.h>
using namespace std;
long double x,y;
int main()
{
cin>>x>>y;
cout<<fixed<<setprecision(2)<<x+y;
return 0;
}
Câu 1:
program Tinhtong:
var
n, i, sum: integer;
begin
write('Nhap n: ');
readln(n);
sum := 0;
for i := 2 to n do
begin
if i mod 2 = 0 then
begin
sum := sum + i;
end;
end;
writeln('Tong cac so chan tu 2 toi ', n, ' la ', sum);
readln;
end.
Câu 2:
program Tinhtong:
var
n, i, sum: integer;
begin
write('Nhap n: ');
readln(n);
sum := 0;
for i := 1 to n do
begin
if i mod 2 = 1 then
begin
sum := sum + i;
end;
end;
writeln('Tong cac so le tu 1 toi ', n, ' la ', sum);
readln;
end.
uses crt;
var a:array[1..10000000] of longint;
i,n,d:longint;
s:real;
begin
clrscr;
s:=1/2;
write('Nhap n la ');readln(n);
for i:=1 to n do
s:=s+(1/(2*i+1));
write('Tong la ',s:0:2);
readln
end.