#include #include typedef struct plural { int real; int imag; struct plural * next; }*node, Node; node creat( int n ); //创建链表函数 void output( node l ); //输出函数 int main() { int n; node head; //链表的头结点 scanf("%d\n", &n); head = creat( n ); //创建链表a output( head ); //输出 return 0; } node creat( int n ) { node h; //头结点指针 h = (node) malloc( sizeof(Node) ); //创建头结点 h->next = NULL; //next指针域赋空 node q = h; //定义指针q,指向头结点 node p; for ( int i = 0; i < n; i++ ) //创建n个结点 { p = (node) malloc( sizeof(Node) ); scanf( "%d%d", &(*p).real, &(*p).imag ); //输入 p->next = q->next; //采用后差法插入节点 q->next = p; q = p; } return h; //返回头结点 } void output( node l ) //输出 { l = l->next; int a=0,b=0; node q; //用于释放结点 while ( l != NULL ) { a+=l->real; b+=l->imag; q=l; l = l->next; free(q); //释放结点 } printf("%d+%di",a,b); }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:511 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:377 |
C语言考试练习题_排列 (C语言代码)浏览:724 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:515 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:612 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:632 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:611 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:862 |
DNA (C语言代码)浏览:540 |
1113题解浏览:789 |