参考代码:
#include <stdio.h> #include <malloc.h> typedef struct linklist { int real,image; struct linklist *next; }ComplexList; ComplexList *CreateList(int n) { ComplexList *head,*p,*q; head=(ComplexList*)malloc(sizeof(ComplexList)); head->next=NULL; q=head; while(n--) { p=(ComplexList*)malloc(sizeof(ComplexList)); scanf("%d%d",&p->real,&p->image); q->next=p; q=p; } q->next=NULL; return head; } void CountList(ComplexList *head) { int sum1=0,sum2=0; ComplexList *p=head; p=p->next; while(p!=NULL) { sum1+=p->real; sum2+=p->image; p=p->next; } printf("%d+%di\n",sum1,sum2); } int main() { int n; scanf("%d",&n); ComplexList *head=CreateList(n); CountList(head); return 0; }
0.0分
7 人评分
C语言训练-大、小写问题 (C语言代码)浏览:612 |
P1000 (C语言代码)浏览:870 |
简单的a+b (C语言代码)浏览:544 |
陶陶摘苹果2 (C语言代码)浏览:597 |
简单的a+b (C语言代码)浏览:507 |
C二级辅导-统计字符 (C语言代码)浏览:632 |
1392题解(大数相加)浏览:602 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:567 |
C二级辅导-求偶数和 (C语言指针动态内存法)浏览:634 |