當前位置:首頁 » 編程語言 » c語言求三角函數sinxcosx
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言求三角函數sinxcosx

發布時間: 2022-08-14 20:01:20

1. c語言。給定x的值,求sinx+cosx的值。

直接調用數學庫的 sin(x) , cos(x) 函數即可。加 頭文件 math.h
#include <stdio.h>
#include <math.h>

int main()
{
double x;
double y;
printf("input x:\n");
scanf("%lf",&x);
y = sin(x) + cos(x);
printf("y=%g\n",y);
return 0;
}

2. c語言編寫三角函數

求sin的:參考下 #include<stdio.h> void main() { double x,a,b,sum=0; printf("請輸入x的弧度值:\n"); scanf("%lf",&x); int i,j,count=0; for(i=1;;i+=2) { count++; a=b=1; for(j=1;j<=i;j++) { a*=x; b*=(double)j; } if(a/b<0.0000001) break; else { if(count%2==0) sum-=a/b; else sum+=a/b; } } printf("%lf\n",sum); }

3. c語言能直接輸入三角函數符號嘛 比如sin cos

可以的
你要在main()之前加個東西#include<math.h>

4. c語言計算三角函數

#include<stdio.h>
#include<math.h>
intmain()
{
doublen;//sincos是函數,不能定義成變數
scanf("%lf",&n);
n=sin(n);//求n的sin()值,並返回給n
printf("%lf ",n);//輸出n
return0;
}

5. 如何用C語言實現三角函數的計算

math.h里的三角函數用的單位是弧度,你貌似錯在這里。 答案補充 Example

/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double pi = 3.1415926535;
double x, y;

x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} 答案補充 Output

sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178

Parameter

x

Angle in radians

6. c語言設計2個子函數分別計算sinx和cosx,要求精度為10(—6)。在主函數中求(sin30+

doublesinx(doublex)
{
doubleresult=x,temp=x;
doubleden=x,fac=1;
intn=1,sign=1;
while((temp>1e-5)||(temp<-1e-5))
{
n++,fac*=n,den*=x;
n++,fac*=n,den*=x;
temp=den/fac;sign=-sign;
result=sign>0?result+temp:result-temp;
}
returnresult;
}

doublecosx(doublex)
{
x=1.57079-x;
returnsinx(x);
}

main()
{
doublea,b,c;
scanf("%lf",&a);
b=sinx(a);
c=cosx(a);
printf("sin(%lf)=%lf,cos(%lf)=%lf",a,b,a,c);
}

7. C語言怎樣表示三角函數計算(註:要用「角度制」表示)編出代碼

調用math.h中的三角函數,需要將角度值變換為弧度值,代碼如下:
#include<stdio.h>
#include<math.h>
#define PI 3.14159265359

int main()
{
float st,a;
scanf("%f",&st);
a = st * PI/180;
printf("sin(st)=%f\n", sin(a));
printf("cos(st)=%f\n", cos(a));
return 0;
}

8. 用C語言輸出CosX,SinX函數圖像的問題,新手求解

把你的printf("*/n")改為printf("*\n"),其它的/n也改為\n看看行不行。
#include <stdio.h>
#include <math.h>
int main()
{
double y;
double x, m, i;
for(y=1;y>=-1;y-=0.1)
{
if(y>=0)
{
m=asin(y)*10;
for(x=1;x<m;x++)
printf(" ");
printf("+");
for(;x<31-m;x++)
printf(" ");
printf("*\n");
}
else
{
m=-1*asin(y)*10;
for(i=0;i<32;i++)
printf(" ");
for(x=1;x<m;x++)
printf(" ");
printf("_");
for(;x<31-m;x++)
printf(" ");
printf("m\n");
m=asin(y)*10;
for(x=1;x<m;x++)
printf(" ");
}
}
return 0;
}

9. C語言三角函數求值,

math.h里的三角函數用的單位是弧度,你貌似錯在這里。 答案補充 Example

/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double pi = 3.1415926535;
double x, y;

x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} 答案補充 Output

sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178

Parameter

x

Angle in radians