当前位置:首页 » 编程语言 » c语言计算三角函数

c语言计算三角函数

发布时间: 2022-05-22 05:52:37

‘壹’ 如何用c语言实现三角函数的计算

包含头文件math.h后,所有三角函数的库函数就都可以直接引用了。比如求x的正弦就用sin(x),它返回一个double值。注意x以弧度计……

‘贰’ c语言计算器怎样做三角函数功能

很简单的,比如你已经有一个表达式char exp[];
那么 char * s = strstr(exp, "sin");
if(s) {
执行sin(alpha)
}
就可以了
strstr是一个字符串函数,用于查找字符串内与关键字匹配的那个位置
比如char exp[] = "cos(a) + sin(b) - tan(c)";
那么char * s = strstr(exp, "sin");
printf(s)的结果是:
sin(b) - tan(c)

‘叁’ 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

‘肆’ 如何用C语言进行三角函数的计算,比如知道sinx=0.5,求cos和tanx。怎么写

在C的math.h是有专门的三角函数和反三角函数的。
所以
你这个
x=asin(0.5)
输出
cos(x)

tan(x)就可以了。

‘伍’ 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;
}

‘陆’ 求三角函数的C语言算法

从键盘输入一个角度值,求出该角度的正弦值、余弦值和正切值。
#include<iostream>
#include<cmath>
using namespace std;
const double pi(3.14159265);
void main()
{ double a,b;
cin>>a;
b=a*pi/180;
cout<<"sin("<<a<<")="<<sin(b)<<endl;
cout<<"cos("<<a<<")="<<cos(b)<<endl;
cout<<"tan("<<a<<")="<<tan(b)<<endl;
}
求阶乘
#include<iostream.h>
int Factorial ( int ) ;
void main ()
{ int k ;
cout << "Compute Factorial(k) , Please input k: " ;
cin >> k ;
cout << k << "! = " << Factorial(k) << endl ;
}
int Factorial ( int n )
{ if ( n == 0 )
return 1 ;
else
return n * Factorial ( n - 1 ) ;
}
x的n次方的函数
#include <iostream>
using namespace std;
double power (double x, int n);
void main(void)
{
cout << "5 to the power 2 is " << power(5,2) << endl;
}
double power (double x, int n)
{
double val = 1.0;
while (n--)
val = val*x;
return(val);
}

‘柒’ C语言中计算三角函数

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

#definePI3.14159265

intmain()
{
doubleans=sqrt((1-cos(PI/3.0))/2.0);
printf("%g ",ans);
return0;
}

‘捌’ 如何用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

‘玖’ 请问C语言中怎么计算三角函数要全部的程序代码!谢谢!

库函数就有啊!
#include<stdio.h>
#include<math.h>
void main()
{
float a,Sin,Cos,Tan,Cot;
printf("请输入你要求三角函数的变量");
scanf("%f" ,&a);
Sin=sin(a); //调用库函数,谭浩强书后面有
Cos=sqrt(1-Sin*Sin);
tan=Sin/Cos;
cot=1/Tan;// 其他的反三角函数也是调用库函数的。你自己搞定吧!
printf("%f,%f,%f,%f" ,Sin,Cos,Tan,Cot);
}

热点内容
linuxcftp服务器 发布:2025-05-14 23:58:18 浏览:716
探岳什么配置才有驾驶模式选择 发布:2025-05-14 23:53:17 浏览:143
如何在手机上看无限流量密码 发布:2025-05-14 23:43:31 浏览:114
19投篮脚本 发布:2025-05-14 23:36:57 浏览:513
编译器怎么处理c变长数组 发布:2025-05-14 23:31:46 浏览:663
存折每天可以输错多少次密码 发布:2025-05-14 23:22:06 浏览:909
安卓手机怎么找微信隐藏对话 发布:2025-05-14 23:07:47 浏览:338
怎么查看泰拉服务器ip 发布:2025-05-14 23:03:29 浏览:74
c语言学生成绩查询系统 发布:2025-05-14 22:58:30 浏览:6
怎么进别人的服务器 发布:2025-05-14 22:45:55 浏览:774