1、绝对值函数(abs,fabs,labs)
#include <stdio.h>
#include <math.h>
void main ( )
{
int X;
printf ( "请输入一个负整数:\n" ) ;
scanf ( "%d" , & X) ;
printf ( "%d的绝对值= %d" , X, abs ( X) ) ;
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X;
printf ( "请输入一个负小数:\n" ) ;
scanf ( "%lf" , & X) ;
printf ( "%lf的绝对值= %lf" , X, fabs ( X) ) ;
}
#include <stdio.h>
#include <math.h>
void main ( )
{
long X;
printf ( "请输入一个负长整型数:\n" ) ;
scanf ( "%ld" , & X) ;
printf ( "%ld的绝对值= %ld" , X, labs ( X) ) ;
}
2、三角函数(cos,sin,tan)
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
void main ( )
{
double angle, cc;
angle= 60.0 ;
cc= cos ( angle* PI/ 180 ) ;
printf ( "X=%lf, cosX=%lf\n" , angle, cc) ;
angle= 120 ;
cc= cos ( angle* PI/ 180 ) ;
printf ( "Y=%lf, cosY=%lf" , angle, cc) ;
}
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
void main ( )
{
double angle, cc;
angle= 30.0 ;
cc= sin ( angle* PI/ 180 ) ;
printf ( "X=%lf, cosX=%lf\n" , angle, cc) ;
angle= 330 ;
cc= sin ( angle* PI/ 180 ) ;
printf ( "Y=%lf, cosY=%lf" , angle, cc) ;
}
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
void main ( )
{
double angle;
angle= - PI/ 4 ;
while ( angle< PI/ 2 )
{
printf ( "X=%lf, tanX=%lf \n" , angle, tan ( angle) ) ;
angle+ = PI/ 8 ;
}
}
3、反三角函数(acos,asin,atan)
#include <stdio.h>
#include <math.h>
void main ( )
{
double X= - 1.0 ;
while ( X<= 1.0 )
{
printf ( "arcos(%-6.3lf)=%.7f\n" , X, acos ( X) ) ;
X+ = 0.4 ;
}
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X= - 1.0 ;
while ( X<= 1.0 )
{
printf ( "arcsin(%-6.3lf)=%.7f\n" , X, asin ( X) ) ;
X+ = 0.4 ;
}
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X= - 2.0 ;
while ( X<= 2.0 )
{
printf ( "arctan(%-6.3lf)=%.7f\n" , X, atan ( X) ) ;
X+ = 0.5 ;
}
}
4、指数和对数函数(exp,log,log10)
#include <stdio.h>
#include <math.h>
void main ( )
{
double X, R;
printf ( "请输入指数:\n" ) ;
scanf ( "%lf" , & X) ;
R= exp ( X) ;
printf ( "e的%lf次方=%lf\n" , X, R) ;
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X, R;
printf ( "请输入真值:\n" ) ;
scanf ( "%lf" , & X) ;
R= log ( X) ;
printf ( "ln(%lf)= %lf\n" , X, R) ;
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X, R;
printf ( "请输入真值:\n" ) ;
scanf ( "%lf" , & X) ;
R= log10 ( X) ;
printf ( "log10(%lf)= %lf\n" , X, R) ;
}
5、幂指数和开方函数(pow,sqrt)
#include <stdio.h>
#include <math.h>
void main ( )
{
double X, Y, R;
printf ( "请输入底数:\n" ) ;
scanf ( "%lf" , & X) ;
printf ( "请输入指数:\n" ) ;
scanf ( "%lf" , & Y) ;
R= pow ( X, Y) ;
printf ( "%lf的%lf次方是%lf" , X, Y, R) ;
}
#include <stdio.h>
#include <math.h>
void main ( )
{
double X, R;
printf ( "请输入需要开方的数:\n" ) ;
scanf ( "%lf" , & X) ;
R= sqrt ( X) ;
printf ( "%lf的开方值= %lf" , X, R) ;
}