#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
typedef struct ListNode{
int data;
ListNode *next;
}ListNode;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int tmp, sum = 0;
float average;
ListNode *head, *p, *q;
scanf("%d", &tmp);
p = (ListNode*)malloc(sizeof(ListNode));
p->data = tmp;
p->next = NULL;
q = p;
head = p;
for(int i = 1; i < 6; i++){
scanf("%d", &tmp);
p = (ListNode*)malloc(sizeof(ListNode));
p->data = tmp;
q->next = p;
q = p;
}
q = head;
for(int i = 0; i < 6; i++){
sum += q->data;
q = q->next;
}
average = sum/6.0;
printf("%f\n", average);
return 0;
}
16. 编写程序,使其具有以下功能: (1) 创建一个能够记录6个任意整数的单向链表。要求:这6个整数必须从键盘获得,并分别保存在链表的不同节点中。 (2) 使用循环语句,遍历已经创建完成的链表,求
最新推荐文章于 2022-08-06 10:10:43 发布