问题标题: 一串代码(计算机)谁能帮我优化一下!!!!!

0
0
已解决
郑皓予
郑皓予
初级光能
初级光能

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    double a,b;
    cin >>a>>b;
    char c;
    cin >>c;
    if(c=='+'){
        cout <<setprecision(2)<<fixed<<a+b;
    }
    else if(c=='-'){
        cout <<setprecision(2)<<fixed<<a-b;
    }
    else if(c=='*'){
        cout <<setprecision(2)<<fixed<<a*b;
    }
    else if(c=='/'&&a!=0&&b!=0){
        cout<<setprecision(2)<<fixed<<a/b;
    }else{
        cout <<"error";
    }
    return 0;
}
 


1
已采纳
於海洋
於海洋
资深光能
资深光能
#include<iostream>
using namespace std;
int main(){
    double a,b;
    cin >>a>>b;
    char c;
    cin >>c;
    if(c=='+'){
        printf("%.2f",a+b);
    }
    else if(c=='-'){
        printf("%.2f",a-b);
    }
    else if(c=='*'){
        printf("%.2f",a*b);
    }
    else if(c=='/'&&a!=0&&b!=0){
        printf("%.2f",a/b);
    }else{
        printf("error");
    }
    return 0;
}

用printf会快一点,是cout的两到三倍

0
曹力维
曹力维
高级守护
高级守护

#include<iostream>
#include<windows.h>
using namespace std;

int main(){
    system("calc");
    return 0;
}

 

好了

0
0
0
我要回答