83!

83 date:2021.2.23
在这里插入图片描述

要点:
求绝对值函数:
fabs() 浮点型
abs() 整型

详细代码如下:

#include   <stdio.h>
#include   <math.h>
double fun(double  x)
{  double  f, t;      int  n;
   f = 1.0 + x;
   t= x;
   n = 1;
   do {
      n++;
      t*=(-1.0)*x/n;
      f += t;
   }
    while(fabs(t) >=1e-6);
   return  f;
}
void main()
{   double x, y;
   x=2.5;
   y = fun(x);
   printf("\nThe result is :\n");
   printf("x=%-12.6f y=%-12.6f\n", x, y);
}

在这里插入图片描述

要点:

详细代码如下:

#include  <math.h>
#include  <stdio.h>
double fun(double x)
{ 
	/*
		analyse:		
		……
	*/

	double s1 = 1.0, p = 1.0, sum = 0.0, s0, t =1.0;

	int n = 1;

	do{
		s0 = s1;
		sum += s0;
		t *= n;
		p *= (0.5-n+1)*x;
		s1 = p/t;
		n++;

	}while(fabs(s1-s0) >= 1e-6);

	return sum;
}
void main()
{ int i;
  double x,s;
  FILE *out;
  printf("Input x: ");
  scanf("%lf",&x);
  s=fun(x);
  printf("s=%f\n ",s);
  /******************************/				 /*这里包含输出文件程序*/
  out=fopen("out.dat","w");
  for(i=20;i<30;i++)
    	fprintf(out,"%f\n",fun(i/100.0));
  fclose(out);
  /******************************/
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值