#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "malloc.h"
#define LEN sizeof(struct Node)
int n;
float m=0;
struct Node
{
float numbers;
struct Node *next;
};
struct Node *creat(void)
{
struct Node *p1,*p2;
struct Node *head;
n=0;
p1=p2=(struct Node *)malloc(LEN);
scanf("%f",&p1->numbers);
head=NULL;
while(p1->numbers!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Node* )malloc(LEN);
scanf("%f",&p1->numbers);
}
p2->next=NULL;
return(head);
}
void print(struct Node *head)
{
struct Node *p;
printf("\nNow,These %d records are :\n",n);
p=head;
if(head!=NULL)
do
{
printf("%f\t",p->numbers);
p=p->next;
}
while(p!=NULL);
}
float mean(struct Node *head)
{
struct Node *p;
p=head;
if(head!=NULL)
do
{
m+=p->numbers;
p=p->next;
}while(p!=NULL);
return m/n;
}
float deviation(struct Node *head)
{
struct Node *p;
float q=0;
p=head;
if(head!=NULL)
do
{
q+=(p->numbers-m/n)*(p->numbers-m/n);
p=p->next;
}while(p!=NULL);
return sqrt(q/(n-1));
}
int main()
{
float x,y;
struct Node *a;
printf("Please input 10 float numbers,end with 0.\n");
a=creat();
print(a);
x=mean(a);
printf("\nThe mean of 10 float numbers is %f",x);
y=deviation(a);
printf("\nThe deviation of 10 float numbers is %f\n",y);
return 0;
}
调试的时候出现警告:
warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
请问一下该怎样改啊?