c語言計算三角函數
『壹』 如何用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);
}