#include
#include
#include
double A1,a1,A2,a2,A3,S1,s1,S2,s2,S3,M1,m1,M2,m2,M3,D1,d1,D2,d2,D3;
double Dsin=0.0,Ds,Dcos=0.0,Dc,Dangle1,dangle1,Dangle2,dangle2,Dradian1,Dradian2,pi=3.1415926;
int i=2,k=2,n;
double add(double A1,double A2)//形参没写数据类型
{
x05A3=A1+A2;
x05printf("答案为:%lfn",A3);
x05return A3;//函数需要返回值
}
double substruction(double S1,double S2)//形参没写数据类型
{
x05S3=S1-S2;
x05printf("答案为:%lfn",S3);
x05return S3;//函数需要返回值
}
double multiplication(double M1,double M2)//形参没写数据类型
{
x05M3=M1*M2;//写成了M3=M1*M1
x05printf("答案为:%lfn",M3);
x05return M3;//函数需要返回值
}
double division(double D1,double D2)//形参没写数据类型
{
x05D3=D1/D2;
x05printf("答案为:%lfn",D3);
x05return D3;//函数需要返回值
}
double Csin(double Dangle1)//形参没写数据类型
{
x05Dradian1=Dangle1*pi/180;
x05Ds=Dangle1*pi/180;
x05while (i<=8)
x05{
x05x05Dsin+=Ds;
x05x05Ds=(-1)*Ds*Dradian1*Dradian1/(i*(i+1));
x05x05i+=2;
x05}
x05printf("答案为:%lfn",Dsin);
x05return Dsin;//函数需要返回值
}
double Ccos(double Dangle2)//形参没写数据类型
{
x05Dradian2=Dangle2*pi/180;
x05Dc=Dangle2*pi/180;
x05while (k<=8)
x05{
x05x05Dcos+=Dc;
x05x05Dc=(-1)*Dc+Dradian2*Dradian2/((k-1)*k);
x05x05k+=2;
x05}
x05printf("答案为:%lfn",Dcos);
x05return Dcos;//函数需要返回值
}
void main()
{
x05printf("输入要进行的运算代码:加法-1,减法-2,乘法-3,除法-4,sin-5,cos-6n");
x05scanf("%d",&n);
x05switch (n)
x05{
x05case 1:
x05x05printf("输入相加的两个数");
x05x05scanf("%lf%lf",&a1,&a2);
x05x05add(a1,a2);
x05x05break;
x05case 2:
x05x05printf("输入减数");
x05x05scanf("%lf",&s1);
x05x05printf("输入被减数");
x05x05scanf("%lf",&s2);//少写了&
x05x05substruction(s1,s2);
x05x05break;
x05case 3:
x05x05printf("输入相乘的两个数");
x05x05scanf("%lf%lf",&m1,&m2);
x05x05multiplication(m1,m2);
x05x05break;
x05case 4:
x05x05printf("输入除数");
x05x05scanf("%lf",&d1);
x05x05printf("输入被除数");
x05x05scanf("%lf",&d2);
x05x05division(d1,d2);
x05x05break;
x05case 5:
x05x05printf("输入要计算的角度");
x05x05scanf("%lf",&dangle1);
x05x05Csin(dangle1);
x05x05break;
x05case 6:
x05x05printf("输入要计算的角度");
x05x05scanf("%lf",&dangle2);
x05x05Ccos(dangle2);
x05x05break;
x05}
}
另外sin跟cos逻辑有问题,算出来是错的