Tuesday, August 12, 2014

1.22 :viết chương trình tính tổng s= 1+ 1/2 + 1/3....+ 1/n với n nguyên dương nhập vào từ bàn phím

#include <conio.h>
#include <stdio.h>

floattong(int n)
{
       int i;
       floats=0;
       for(i=1;i<=n;i++)
              s+=1.0/i;
       return s;
}
voidmain()
{
       int n;
       printf("\nNhap N=   ");
       scanf("%d",&n);
       printf("\n Tong s = %f",tong(n));
       getch();
}


No comments:

Post a Comment