c++数学作业辅助神器
在DEV-c++里运行
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a;
int main() {
while (1) {
cout << "你需要什么" << endl << "计算器按1" << endl << "计算幂次方按2" << endl << "计算绝对值按3" << endl << "开平方按4" << endl << "开立方按5" << endl << "比较大小按6" << endl << "排序按7" << endl<<"时间换算按8"<<endl<<"进制转换按9"<<endl<< "禁止错误输入" << endl<<"请输入:";
cin >> a;
cout<<endl;
if (a == 1) {
double a, c;
char b;
scanf("%lf%c%lf", &a, &b, &c);
if (b == '*') {
cout << a*c;
} else if (b == '+') {
cout << a + c;
} else if (b == '-') {
cout << a - c;
} else if (b == '/') {
if (c == 0) {
cout << "错误";
} else {
cout << a / c;
}
}
} else if (a == 2) {
int a, b;
cin >> a >> b;
cout << pow(a, b);
} else if (a == 3) {
int a;
cin >> a;
cout << abs(a);
} else if (a == 4) {
long long a;
cin >> a;
cout << sqrt(a);
} else if (a == 5) {
long long a;
cin >> a;
cout << cbrt(a);
} else if (a == 6) {
long long a, b, c;
cin >> a >> b;
c = max(a, b);
if (c == a) {
cout << ">";
} else if (c == b) {
cout << '<';
} else {
cout << "=";
}
} else if (a == 7) {
int a, b, c[1000];
cout << "升序输出按1"<<endl;
cout << "降序输出按2"<<endl;
cin >> b;
cin >> a;
for (int i = 1; i <= a; i++) {
cin >> c[i];
}
for (int i = 1; i <= a; i++) {
for (int j = i; j <= a; j++) {
if (c[i] < c[j]) {
swap(c[i], c[j]);
}
}
}
if (b == 1) {
for (int i = 1; i <= a; i++) {
cout << c[i] << " ";
}
} else if (b == 2) {
for (int i = a; i >= 1; i--) {
cout << c[i] << " ";
}
}
cout << endl;
}
else if(a==8){
int fen,shi,fen1,miao;
cout<<"输入单位时间为分的时间:";
cin>>fen;
shi=fen/60;
fen1=fen%60;
if(shi==0){
cout<<fen;
}
else {
cout<<shi<<"时"<<fen1<<"分"<<endl;
}
}
else if(a==9)
{
char q[100];
long n=0;
int i,l,r=0,p,c,m=0,s[100];
cout<<"输入要转化的数:";
cin>>q;
cout<<"输入原数进制:";
cin>>i;
cout<<"转换后的进制:";
cin>>p;
l=strlen(q);
strupr(q);
for(l=l-1;l>=0;l--)
{if(q[l]<='9')n=n+(q[l]-48)*pow(i,r++);
else n=n+(q[l]-55)*pow(i,r++);}
while(n!=0)
{ c=n%p;
n=n/p;
m++;
s[m]=c;
}
for(int k=m;k>=1;k--)
{
if(s[k]>=10)
{
cout<<(char)(s[k]+55);
Sleep(250);
}
else
cout<<s[k];
Sleep(250);
}
cout<<endl<<endl;
}
}
return 0;
}
有bug及时联系
记得点赞
散会