程序如:
/*此为多项式相加的程序*/
#include<stdio.h>
#include<dos.h>
typedef struct node
{float xs;
int zs;
struct node *next;
}node; /*类型定义*/
int N=sizeof(node);
node * creat() /*定义多项式生成函数*/
{node *p,*h,*ph;
p=(node *)malloc(N); /*开辟头节点*/
sleep(5);
scanf("%f,%d",&p->xs,&p->zs);
ph=h=p;
while(ph->xs!=0)
{p=(node *)malloc(N);
scanf("%f,%d",&p->xs,&p->zs);
ph->next=p;
ph=ph->next;
}
ph->next=NULL;
return h;
}
node *dxsadd(node *s1,node *s2) /*定义多项式相加函数*/
{ node *p=(node *)malloc(N),*p1=p;
while(s1->xs&&s2->xs)
if ( s1->zs>s2->zs)
{ p1->next=s1;
s1=s1->next;
}
else if ( s1->next<s2->next)
{ p1->next=s2;
s2=s2->next;
}
else if ((s1->xs+s2->xs)==0)
{ s1=s1->next;
s2=s2->next;
}
else {s1->xs=s1->xs+s2->xs;
p1->next=s1;
s1=s1->next;
s2=s2->next;
}
if ( s1->xs)
{ p1->next=s1;
}
if ( s2->next)
{ p1->next=s2;
}
return p;
}
void print(node *p) /*定义输出函数*/
{while ( p->xs)
{ printf("%.2f %d ",p->xs,p->zs);
}
printf("\n\n");
}
main()
{node *s1,*s2,*p;
printf("please input s1:\n");
s1=creat();
printf("please input s2:\n");
s2=creat();
p=dxsadd(s1,s2);
printf("the added : ");
print(p->next);
}
为什么运行时出现
scanf:floating point formats not linked
Abnormal program termination?
[此贴子已经被作者于2006-3-28 21:13:27编辑过]