• 算法训练 P1103


    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    struct num{
        double a;
        double b;
    };
    void add(struct num A, struct num B, struct num* C);
    void sub(struct num A, struct num B, struct num* C);
    void mul(struct num A, struct num B, struct num* C);
    void div(struct num A, struct num B, struct num* C);
    void clac(char op, struct num A, struct num B, struct num* C);
    
    void clac(char op, struct num A, struct num B, struct num* C){
    
        switch(op){
            case '+': add(A,B,C); break;
            case '-': sub(A,B,C); break;
            case '*': mul(A,B,C); break;
            case '/': div(A,B,C); break;
        }
    }
    
    void add(struct num A, struct num B, struct num* C){
        C->a = A.a + B.a;
        C->b = A.b + B.b;
    }
    
    void sub(struct num A, struct num B, struct num* C){
        C->a = A.a - B.a;
        C->b = A.b - B.b;
    }
    
    void mul(struct num A, struct num B, struct num* C){
        C->a = A.a*B.a - A.b*B.b;
        C->b = A.a*B.b + A.b*B.a;
    }
    
    void div(struct num A, struct num B, struct num* C){
        double x = B.a*B.a + B.b*B.b;
        C->a = (A.a*B.a + A.b*B.b)/x;
        C->b = (A.b*B.a - A.a*B.b)/x;
    }
    
    int main(){
        struct num A;
        struct num B;
        struct num C;
        char op;
        cin >> op >> A.a >> A.b >> B.a >> B.b;
        clac(op, A,B,&C);
        printf("%.2f+%.2fi
    ", C.a, C.b);
    
        return 0;
    }
  • 相关阅读:
    连接查询
    使用聚合函数查询
    mysql 查询数据
    Mysql的基本操作
    MySQL的数据类型
    Mysql简介及安装教程
    客户端-服务端
    configparser模块
    反射
    class_method和static_method
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538130.html
Copyright © 2020-2023  润新知