You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <iostream>
# include <stdio.h>
# include <math.h>
# define pi 3.14
using namespace std ;
const double e = 2.718281828459 ;
int san ( )
{
int a ;
double b ;
printf ( " 请输入你要计算的角度b: " ) ;
scanf ( " %d " , & a ) ;
b = a * pi / 180 ;
printf ( " sin(b)=%f \n " , sin ( b ) ) ;
printf ( " cos(b)=%f \n " , cos ( b ) ) ;
printf ( " tan(b)=%f \n " , tan ( b ) ) ;
return 0 ;
}
int exp ( )
{
int x ;
double y ;
printf ( " please input x: " ) ;
scanf ( " %d " , & x ) ;
if ( x > 0 )
{
y = exp ( x ) ;
}
else if ( x < 0 )
{
y = exp ( x ) ;
}
else
{
printf ( " y==1 \n " ) ;
}
printf ( " y=%f \n " , y ) ;
}
double log ( double x )
{
long t = 0 ;
while ( x > 1 )
{
x / = e ;
+ + t ;
}
x = x - 1 ;
double ret = 0 ;
int k = 1 ;
double temp ;
double c = 1 ;
double xx = 1 ;
while ( 1 )
{
xx * = x ;
temp = c * xx / k ;
c * = - 1 ;
ret + = temp ;
+ + k ;
if ( temp > - 0.00000001 )
break ;
}
return ret + t ;
}
int log2 ( )
{
double a , x ; // 计算log(a,x);
// 用ln(x)/ln(a)计算。
cin > > a > > x ;
if ( a < = 0 | | x < = 0 | | a = = 1 )
{
cout < < " 输入不正确! " < < endl ;
}
double ans = log ( x ) / log ( a ) ;
cout < < ans < < endl ; // log(x)返回x的自然对数, 使用虚include"cmath"或"math.h"。
return 0 ;
}
int add ( )
{
int a , b , d ;
char c ;
printf ( " 输入运算式: " ) ;
scanf ( " %d%c%d " , & a , & c , & b ) ;
switch ( c )
{
case ' + ' : d = a + b ; break ;
case ' - ' : d = a - b ; break ;
case ' * ' : d = a * b ; break ;
case ' / ' : d = a / b ; break ;
}
printf ( " %d%c%d=%d \n " , a , c , b , d ) ;
}
int main ( )
{
san ( ) ;
exp ( ) ;
log2 ( ) ;
add ( ) ;
return 0 ;
}