當前位置:首頁 » 編程語言 » 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);
}
}

望採納