Kết quả sai khi tính tổng chuỗi 1/n^2

Tính tổng
image

#include <stdio.h>
#include <math.h>

int main()
{
    int i, n;
    float s = 0;

    printf("Nhap n: ");
    printf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        s = s + 1/(i *i);
    }

    printf("Ket qua: %f", s);
    return 0;
}

Output

Nhap n: 1
Ket qua: 1.000000
-------------------------------
Process exited after 4.729 seconds with return value 0
Press any key to continue...

sửa thành 1.0 / (i*i) nhé

2 Likes

dạ e cảm ơn…ra kết quả rồi ạ

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?