解题思路: 注意事项: 参考代码: #include<stdlib.h> #include<stdio.h> typedef struct node { int real; //实部 int imaginary; //虚部 struct node *next; }Node; Node *creatnode(Node *head, int real, int imaginary) { Node *node = (Node *)malloc(sizeof(Node)); node->real = real; node->imaginary = imaginary; node->next = NULL; if (!node) { printf("申请内存失败"); exit(0); } if (!head) { head = node; } else { node->next = head; head = node; } return head; } int main() { int n, i, real, imaginary, sum1 = 0, sum2 = 0; scanf("%d", &n); Node *head = NULL; for (i = 0; i < n; i++) { scanf("%d %d", &real, &imaginary); head = creatnode(head, real, imaginary); } Node *p = head; while (p) { sum1 += p->real; sum2 += p->imaginary; p = p->next; } printf("%d+%di", sum1, sum2); return 0; }
0.0分
0 人评分
数列 (C++代码)浏览:707 |
【绝对值排序】 (C++代码)浏览:720 |
三角形 (C语言代码)浏览:965 |
Hello, world! (C++代码)浏览:1778 |
字符逆序 (C语言代码)浏览:645 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:420 |
幸运数 (C++代码)浏览:2982 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:399 |
字符串对比 (C++代码)浏览:597 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:687 |