lập trình tính tổng 1/2+1/3+-+1/n với n nhập từ bàn phím với lệnh while…do 14/08/2021 Bởi Clara lập trình tính tổng 1/2+1/3+….+1/n với n nhập từ bàn phím với lệnh while…do
program oken; uses crt; var a: real; i,n:longint; begin clrscr; write(‘nhap n: ‘); readln(n); a:=0; i:=1; while i<=n do begin a:=a+1/i; i:=i+1; end; writeln(‘A=’,a:0:3); readln; end. Bình luận
ko while do dc ko ban =( #include<bits/stdc++.h>using namespace std;int main(){ double n,total=0; cin>>n; for(int i=1;i<=n;i++){ total+=1/(float)i; } cout<<total; //samon247 return 0;} Bình luận
program oken;
uses crt;
var a: real;
i,n:longint;
begin
clrscr;
write(‘nhap n: ‘); readln(n);
a:=0; i:=1;
while i<=n do
begin
a:=a+1/i;
i:=i+1;
end;
writeln(‘A=’,a:0:3);
readln;
end.
ko while do dc ko ban =(
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,total=0;
cin>>n;
for(int i=1;i<=n;i++){
total+=1/(float)i;
}
cout<<total;
//samon247
return 0;
}