10(不要用强转 t-= (double)1/i; 系统设定了唯一方式)

在这里插入图片描述

详细代码如下:

#include  <stdlib.h>
#include  <conio.h>
#include  <stdio.h>
double fun(int m)
{
    
    
  double t=1.0;
  int i;
  for(i=2;i<=m;i++)
/*************found**************/
      t-=1.0/i;  // 不要用强转  t-= (double)1/i; 系统设定了唯一方式
/*************found**************/
      return t;
}
void main()
{
    
    int m;
 system("CLS");
 printf("\nPlease enter 1 integer numbers:\n");
 scanf("%d",&m);
 printf("\n\nThe result is %1f\n",
 fun(m));
}

猜你喜欢

转载自blog.csdn.net/weixin_44856544/article/details/115218327