#include <stdio.h> #include <malloc.h> typedef struct plural { int real; int imag; struct plural * next; }*node, Node; node creat( int n ); //创建链表函数 void output( node l ); //输出函数 int main() { int n=10; node head; //链表的头结点 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语言训练-排序问题<1> (C语言代码)浏览:601 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:262 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:558 |
字符串输入输出函数 (C语言代码)浏览:2495 |
简单的a+b (C语言代码)浏览:540 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:537 |
【计算球体积】 (C语言代码)浏览:1550 |
检查金币 (C语言代码)浏览:1415 |
简单的a+b (C语言代码)浏览:558 |
C语言程序设计教程(第三版)课后习题8.3 (C++代码)浏览:508 |