Code tính tổng 1/i! (i = 1 -> n) bị sai

Mọi người xem mình sai ở chỗ nào với!Mình cảm ơn trước ạ.Đề bài: tình tổng 1/i! (i chạy từ 1)

#include<stdio.h>
#include<conio.h>
#include<math.h>
int enter()
{
	int n;
	do{
		printf("Enter n: ");
		scanf("%d",&n);
	}while(n<1);
	return n;
}
float sum_f(int n)
{
	int i,gt=1;
	float f=0;
	for(i=1; i<=n; i++)
	{
		gt=gt*i;
		f=f+1.0/gt;
	}
	return f;
}
main()
{
	int n;
	float f;
	n=enter();
	f=sum_f(n);
	printf("Sum of part A is %f",f);
	getch();
}

Mình thấy có gì sai đâu nhỉ, có thể là IDE của bạn chăng. (Thấy thừa mỗi math library) :smile:
Input: 4.
Run result: 1.70833333333
Link :point_right: https://ideone.com/2DwK7a

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