给你一个只有四则运算的6的2.4次方用计算器怎么算,怎么计算3.14的π次方减去π的3.14次方?

#include<stdio.h>
void mygcd(int m1, int n1){
int t;
int m = m1;
int n = n1;
while(1){
if(n > m){
t = m;
m = n;
n = t;
}
else{
t = m % n;
if(t == 0)
break;
m = n;
n = t;
}
}
m1 /= n;
n1 /= n;
printf("%d/%d", m1, n1);
}
int computeplus(int a, int b, int c, int d){
int answerup;
answerup = a*d + c*b;
return answerup;
}//加法分子
int computesub(int a, int b, int c, int d){
int answerup;
answerup = a*d - c*b;
return answerup;
}//减法分子
int computemult(int a, int b){
int answer;
answer = a*b;
return answer;
}//乘法分子
int computedown(int a, int b){
int answerdown;
answerdown = a*b;
return answerdown;
}//分母
int main() {
#define MAX 1000
int i = 0;int tempup,tempdown;
int j = 0;int t;
int number[MAX];
char signal[MAX];
while(scanf("%d/%d%c", &number[i++], &number[i++], &signal[j++]) != EOF)
;
t = i;
for(i = j = 0; i < t-4 ; ++j){
if(signal[j] == '+'){
tempup = computeplus(number[i+1], number[i], number[i+3], number[i+2]);
tempdown = computedown(number[i], number[i+2]);
i += 2;
number[i] = tempdown;
number[i+1] = tempup;
tempup = tempdown = 0;
}
else if(signal[j] == '-'){
tempup = computesub(number[i+1], number[i], number[i+3], number[i+2]);
tempdown = computedown(number[i], number[i+2]);
i += 2;
number[i] = tempdown;
number[i+1] = tempup;
tempup = tempdown = 0;
}
else if(signal[j] == '*'){
tempup = computemult( number[i+1],number[i+3]);
tempdown = tempdown = computedown(number[i], number[i+2]);
i += 2;
number[i] = tempdown;
number[i+1] = tempup;
tempup = tempdown = 0;
}
else if(signal[j] == '/'){
tempup = computemult( number[i+1],number[i+2]);
tempdown = computedown(number[i], number[i+3]);
i += 2;
number[i] = tempdown;
number[i+1] = tempup;
tempup = tempdown = 0;
}
}
mygcd(number[i+1], number[i]);
}

身份认证 购VIP最低享 7 折!
领优惠券(最高得80元)
此文件为计算器c++源码,实现了计算器中的四则运算与次方运算,运算方法为从左往右依次运算(不支持括号)资源推荐资源评论光影shaders
粉丝: 0
资源: 1资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈

我要回帖

更多关于 6的2.4次方用计算器怎么算 的文章

 

随机推荐