Cho mình hỏi làm sao tính được tổng 1/2+1/4+1/6…+1/2n vậy mọi người?
#include<stdio.h>
int main()
{ float x,i=1;
float y=0;
float n;
printf("nhap x:");
scanf("%f",&x);
do{
if(x>0){
y=y+(float)n/i;
i++;
n++; }
else
printf("xin ban nhap lai \n ");
} while(i<=x );
if(y>0)
printf("x=%0.1f",y);
return 0;
}
EDIT (@library):
Friendly reminder, @huyen_cao cậu nhớ chú ý các điểm sau ở các post tiếp theo nhé:
- Dùng markdown để format code
- Đặt tên topic ngắn gọn
- Phân loại topic và tag phù hợp