QUESTION
To find the mean of the elements of the array.
“TESTCASE_1”: “5\n1 2 3 4 5\n###—###SEPERATOR—###—\n3.00”, “TESTCASE_2”: “6\n1 2 5 41 23 1\n###—###SEPERATOR—###—\n12.17”, “TESTCASE_3”: “4\n2 3 78 45\n###—###SEPERATOR—###—\n32.00”, “TESTCASE_4”: “8\n-8 -9 -7 45 12 0 36 45\n###—###SEPERATOR—###—\n14.25”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0
ANSWER
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}Node;
Node *head;
Node *tr;
Node *prev;
void insert(int n)
{
Node *temp=(Node*)malloc(sizeof(Node));
temp->data=n;
if(head==NULL)
{
head=temp;
head->next=NULL;
}
else
{
tr=head;
while(tr->next!=NULL)
{
tr=tr->next;
}
tr->next=temp;
tr=tr->next;
tr->next=NULL;
}
}
void display(int n)
{
double sum=0;
if(head==NULL)
{
printf("NULL");
}
else
{
tr=head;
while(tr->next!=NULL)
{
sum=sum+(double)tr->data;
//printf("%d->",tr->data);
tr=tr->next;
}
sum=sum+(double)tr->data;
printf("%.2f",sum/n);
}
}
int main()
{
int n;
scanf("%d",&n);
int data[100];
//n=strlen(data);
int i;
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);
insert(data[i]);
}
//deletion();
display(n);
return 0;
}