VL04 - Tính tổng S = 1/2 + 1/3 + ... + 1/n
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift
Viết chương trình tìm ~S~ biết: $$S = \frac{1}{2} + \frac{1}{3} + ... + \frac{1}{n}$$
Trong đó ~n~ là số nguyên dương, ~ 2 \le n \le 10^4 ~
Input
Số nguyên dương ~n~
Output
Giá trị ~S~ làm tròn đến chữ số thập phân thứ 4
Sample
Input #1
2
Output #1
0.5000
Bình luận
include <iostream>
include <iomanip>
using namespace std;
int main() { int n; cin >> n; double S = 0; for (int i = 2; i <= n; i++) { S += 1.0 / i; }
}
mj #defkine ll long long us king nmkmamespace std; ll r4fnkmkkmmtk =0; int main() { cvgrgv(v){ g tvg+=(1.0/i);k v}k v cout<<vg<<b (4)<<t<<endl; return 0 gv ; } hdhrfrfrfgbrhfr
using namespace std; int main() { int n; cin>>n; if(n==2){cout<<fixed<<setprecision(4)<<(1.0/n); return 0;} float tong=(1.0/2.0+1.0/n)*(n-1)/2; cout<<fixed<<setprecision(4)<<tong; return 0; } cũng sai nốt
sai
helo
ae giups pls
full ac : xin 1 luot vote
include <iostream>
include <iomanip>
using namespace std;
int main() { int n; cin >> n;
}
n = int(input()) print(f"{sum(1/i for i in range(2, n + 1)):.4f}") đây nhé
tiếp tục là python; n=int(input().strip()) s=0 i=2 for i in range(2, n + 1): s+=1.0/i print("{:.4f}".format(s))
Bình luận này đã bị ẩn vì có quá nhiều phản ứng tiêu cực. Nhấn để xem.
FULL AC:
include <bits/stdc++.h>
using namespace std; int main() { int n; cin>>n; if(n==2){cout<<fixed<<setprecision(4)<<(1.0/n); return 0;} float tong=(1.0/2.0+1.0/n)*(n-1)/2; cout<<fixed<<setprecision(4)<<tong; return 0; }
include <bits/stdc++.h>
using namespace std; int main() { int n; cin>>n; if(n==2){cout<<fixed<<setprecision(4)<<(1.0/n); return 0;} float tong=(1.0/2.0+1.0/n)*(n-1)/2; cout<<fixed<<setprecision(4)<<tong; return 0; } //đúng ko ae?
Chac la thieu vong lap for nha ban
67
???
ai chỉ tôi bài này được không
tôi chỉ cho nek
include <bits/stdc++.h>
include <iomanip>
using namespace std; int n,i; int main() { cin >> n; if (n < 2 || n > 10000) { cout << "INVALID"; return 0; } double S = 0; for ( i = 2; i <= n; i++) { S += 1.0 / i; } cout << fixed << setprecision(4) << S; return 0; }
skibidi toilet
hello anh em
hello ae hihi
hello bạn f(x)=x^2
hello ae
s += (double)1/i;
Không sai đâu em