|
发表于 2023-11-11 14:57:08
|
显示全部楼层
本楼为最佳答案
- #include <stdio.h>
- typedef struct {
- float x;
- float y;
- } Comp;
- void add(Comp c1, Comp c2) {
- float real = c1.x + c2.x;
- float imag = c1.y + c2.y;
- if (imag >= 0) {
- printf("%.2f+%.2fi\n", real, imag);
- } else {
- printf("%.2f%.2fi\n", real, imag);
- }
- }
- void subtract(Comp c1, Comp c2) {
- float real = c1.x - c2.x;
- float imag = c1.y - c2.y;
- if (imag >= 0) {
- printf("%.2f+%.2fi\n", real, imag);
- } else {
- printf("%.2f%.2fi\n", real, imag);
- }
- }
- int main() {
- Comp c1, c2;
- scanf("%f%f%f%f", &c1.x, &c1.y, &c2.x, &c2.y);
- add(c1, c2);
- subtract(c1, c2);
- return 0;
- }
复制代码 |
|