题目:编写结构体,能实现复数的四则运算(分母为0时合理跳出)
个人代码实现:
#include <stdio.h>
typedef struct Complex{
float realpart;
float imagpart;
}Complex;
float getReal(Complex *A) {
return A->realpart;
}
float getImag(Complex *A) {
return A->imagpart;
}
void assign(Complex *A, float real, float imag) {
A->realpart = real;
A->imagpart = imag;
}
void add(Complex *A, Complex B, Complex C) {
A->realpart = B.realpart + C.realpart;
A->imagpart = B.imagpart + C.imagpart;
}
void minus(Complex *A, Complex B, Complex C) {
A->realpart = B.realpart - C.realpart;
A->imagpart = B.imagpart - C.imagpart;
}
void multiply(Complex *A, Complex B, Comple