Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Hướng dẫn em code bài này với ạ (sử dụng C++ nhé)

2 năm trước 414 lượt xem 2 bình luận 2 năm trước

S=1 + 1/2^2 + 1/3^2 + ... + 1/n^2

 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
Sygma2002 đã bình luận 2 năm trước

phân tích ra mà làm chớ bạn. 

shikuu1109 đã bình luận 2 năm trước

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;
    double sum = 0.0;

    cout << "Enter the value of n: ";
    cin >> n;

    // Calculate the sum of the series
    for (int i = 1; i <= n; i++) {
        sum += 1.0 / pow(i, 2);
    }

    // Display the result
    cout << "The sum of the series is: " << sum << endl;

    return 0;
}
 

 

Câu hỏi mới nhất