当前位置:首页 » 编程语言 » c语言构造sinx
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言构造sinx

发布时间: 2022-07-08 23:00:02

A. 怎样用c语言编写x=sinx

你是要用系统库函数还是……
想用数值方法自己算?
用库函数就#inclue <math.h>
直接可以调用double sin(double x);
数值方法的话,将sin(x)泰勒展开,
令最末项o(n)<需要的精度。

B. 如何用c语言画出y=sinx的图像。要求水平为x轴,竖直方向为y轴,不允许使用数学库。意思是要自己定义函数。

#include<stdio.h>
#include<math.h>
#define pi 3.1415926
#define MAX_W 50000
main()
{
void sin_curv(int w, int h, int ang);
int w,h,ang;
scanf("%d %d %d",&w,&h,&ang);
sin_curv(w,h,ang);
return 0;
}
void sin_curv(int w, int h, int ang)
{
char str[MAX_W];
int s,i,j;
double d;
for(i=0;i<h;i++)
{
for(s=0;s<w;s++)
str[s]=' ';
str[0]='|';
str[w]='\0';
if(i==h/2)
{
for(s=1;s<w;s++)
str[s]='-';
}
for(j=0;j<w;j++)
{
d=j*ang/w*pi/180.0;
if(i==(int)(h/2-sin(d)*h/2))
str[j]='*';
}
puts(str);
}
}

望采纳