Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
29
Добавлен:
17.04.2013
Размер:
1.1 Кб
Скачать
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct list
{
	int info;
	list *next;
};

void New(list* &head, list* &tail)
{
	head=new list;
	head->info=random(10);
	head->next=NULL;
	tail=head;
}

void Add(list* &tail)
{
	list *T;

	T=new list;
	T->info=random(10);
	T->next=NULL;
	tail->next=T;
	tail=T;
}


float Averange(list *head, list *tail)
{
	list *T;
	int s=0, n=0;

	T=head;
	while (T!=tail)
	{
		n++;
		s+=T->info;
		T=T->next;
	}
	n++;
	s+=tail->info;

	return float(s)/float(n);
}

void Print(list *head, list *tail)
{
	list *T;

	T=new list;
	T=head;
	while (T!=tail)
	{
		printf("%d ",T->info);
		T=T->next;
	}
	printf("%d ",tail->info);
}

void main()
{
	clrscr();
	randomize();

	list *head, *tail;
	int i, n;
	float a;

	printf("Enter number of elements: ");
	scanf("%d",&n);

	if (n==0)
		return;

	New(head,tail);
	for (i=1;i<=n-1;i++)
		Add(tail);
	printf("Your list: ");
	Print(head,tail);

	a=Averange(head,tail);
	printf("\nAverange is: %.3f", a);

	getch();
}
Соседние файлы в папке Lab3