求一个简单的C++程序,最好带注释,什么都行
展开全部
#include<iostream> #include<cmath> int jie(int ); using namespace std; long int main() {L: char a; cout<<"a.求幂\n"<<"b.求e的多次方\n"<<"c.开根号\n"<<"d.求对数log\n"<<"e.求对数ln\n"<<"f.求三角函数\n"<<"g.阶乘\n"<<"h.加减乘除"<<endl; cout<<"选择:"; cin.clear(); cin>>a; switch(a) { case 'a':{double b,c;cout<<"输入底数:"; cin>>b; cout<<"输入次方:";cin>>c; cout<<b<<"^"<<c<<"="<<pow(b,c)<<endl; }break; case 'b':{double b;cout<<"输入e的次方";cin>>b; cout<<"e^"<<b<<"="<<exp(b);}break; case 'c':{double b;cout<<"输入要开平方的数:";cin>>b; cout<<"结果是:"<<sqrt(b)<<endl;}break; case 'd':{double b,d;cout<<"输入底数:";cin>>d; cout<<"输入真数:";cin>>b; cout<<"log"<<d<<"("<<b<<")="<<(log(b)/log(d))<<endl;}break; case 'e':{double b;cout<<"输入真数:";cin>>b; cout<<"ln"<<b<<"="<<log(b)<<endl;}break; case 'f':{char q;cout<<"a.sin()\n"<<"b.cos()\n"<<"c.tan()\n"<<"d.arcsin()\n"<<"e.arccos()\n"<<"f.arctan()\n"<<"g.cot()\n"<<"选择:"; cin>>q; switch(q) { case 'a':{double c;cout<<"输入角度";cin>>c; cout<<"sin"<<c<<"="<<sin(c)<<endl;}break; case 'b':{double c;cout<<"输入角度";cin>>c; cout<<"cos"<<c<<"="<<cos(c)<<endl;}break; case 'c':{double c;cout<<"输入角度";cin>>c; cout<<"tan"<<c<<"="<<tan(c)<<endl;}break; case 'd':{double c;cout<<"输入";cin>>c; cout<<"arcsin"<<c<<"="<<asin(c)<<endl;}break; case 'e':{double c;cout<<"输入";cin>>c; cout<<"arccos"<<c<<"="<<acos(c)<<endl;}break; case 'f':{double c;cout<<"输入";cin>>c; cout<<"arctan"<<c<<"="<<atan(c)<<endl;}break; case 'g':{double c;cout<<"输入角度";cin>>c; cout<<"cot"<<c<<"="<<(cos(c)/sin(c))<<endl;}break; default :cout<<"error"<<endl; }break; } case 'g':{int a;cout<<"输入:";cin>>a;cout<<"结果是:"<<jie(a)<<endl;}break; case 'h':{char ch;double m,n;cout<<"输入:";cin>>m>>ch>>n; switch (ch) {case '+':cout<<m<<"+"<<n<<"="<<m+n<<endl;break; case '-':cout<<m<<"-"<<n<<"="<<m-n<<endl;break; case '*':cout<<m<<"*"<<n<<"="<<m*n<<endl;break; case '/':cout<<m<<"/"<<n<<"="<<m/n<<endl;break; default :cout<<"error"<<endl; }break; default :cout<<"error"<<endl; } } cout<<endl; cout<<endl; goto L; } int jie(int n) { if(n==0)return 1; else return n*jie(n-1); } 实现简单的计算器功能
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询