kwhw.net
当前位置:首页 >> C语言 使用函数求余弦函数的近似值 >>

C语言 使用函数求余弦函数的近似值

#include #include int main(void) { double x, e,cosx; double funcos(double e,int x); printf("e: "); scanf("%lf",&e); printf("x: "); scanf("%lf",&x); //这里是%lf cosx=funcos(e,x); printf("cos(x)=%.3f\n",cosx); return 0; } double ...

double funcos(double e, double x){ if(e>0) { int i=0; double item=1; double cosx=0; while(fabs(item)>=e) { cosx+=item; i++; item*=-1*x*x/(2*i*(2*i-1)) } return cosx; } else return -2;}

不知道题目的目的是考读写格式还是计算。假定是计算,程序如下: #include #include #include double funcos(double e,double x){ double sum=1.0,term=1; int i2=0,x2; while(1){ term= (-1) * term*x/(i2+1) *x /(i2+2); sum=sum+term; i2=i2+...

double funcos(double e,double x){ double cos=0;t=x; int n=1,f=1; while(t>e){ cos += f*t; t *= (x*x/n/(n+1); n += 2; f=-f; }}

int power(int a, int n){//a代表底数,n代表指数if(n == 0) return 1;else return a * power(a, n -1);}int fac(int n){//计算n!if(n == 0) return 1;else return n * fac(n - 1);}

#include "stdio.h" #include "math.h" double funcos(double e, double x); int main(void) { int repeat, ri; double e, sum, x; scanf("%d", &repeat); for(ri = 1; ri =e){ if(d=0){dm=1;} else{for(i=1;i

C:\Users\Administrator\Desktop\My Project\test.cpp: In function 'double fact(double)': C:\Users\Administrator\Desktop\My Project\test.cpp:8:26: error: 'n' was not declared in this scope for (double j = 1; j

反3角函数有 acos(double),asin(double),atan(double),atan(double,double),返回值 double 型,弧度值。转角度要 *180.0/3.1416。 例如: 1、#include 2、#include 3、#include 4、int main() 5、{double x=0.5; printf("acos=%.2lf degrees\n",...

C语言的三角函数库采用的单位都是弧度,如果要使用角度,就必须转换,从角度转换成弧度,或者是重写一个三角函数库。 方法一,在调用三角函数之前先把角度换算成弧度,调用反三角函数之后把弧度换算成角度就可以了。可以用 pi = 4.0 * atan(1) ...

#include #include #define P 3.1415927double sinx(double x) {double eps = 1E-8,delta = x;double sgn = -1,sin = x,n = 1;double nator = 1;while(fabs(delta) > eps) {nator *= (n + 1.0)*(n + 2.0);delta *= x*x/nator;sin += sgn*delta;...

网站首页 | 网站地图
All rights reserved Powered by www.kwhw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com