解题思路:
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
typedef struct _node
{
int i;
int j;
struct _node* next;
}NODE;
NODE* add(NODE* head, int i, int j);
NODE addition(NODE* head);//创建节点
int main()
{
int i = 0;
int j = 0;
int cnt = 0;
NODE* head = NULL;
do
{
scanf("%d%d", &i, &j);
head = add(head, i, j);
} while ((++cnt) <= 9);
NODE p = addition(head);
printf("%d+%di", p.i, p.j);
}
NODE addition(NODE* head)//加法
{
NODE* move = head;
int real = 0;
int virt = 0;
int cnt = 0;
do
{
real += move->i;
virt += move->j;
move = move->next;
} while ((++cnt) <= 9);
NODE p;
p.i = real;
p.j = virt;
p.next = NULL;
return p;
}
NODE* add(NODE* head, int i, int j)
{
NODE* p = (NODE*)malloc(sizeof(NODE));
p->i = i;
p->j = j;
NODE* last = head;
if (last)
{
while (last->next)
{
last = last->next;
}
last->next = p;
}
else
{
head = p;
}
return head;
}
0.0分
0 人评分
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:502 |
时间转换 (Java代码)浏览:617 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:573 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:689 |
A+B for Input-Output Practice (IV) (C++代码)浏览:713 |
小明A+B (C语言代码)浏览:1316 |
校门外的树 (C语言代码)浏览:988 |
C语言训练-求PI* (C语言代码)浏览:638 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:509 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:552 |