| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 955 人关注过本帖
标题:求助:这个多项式相乘哪错了,它一个错误:in,syntax error at end of input
只看楼主 加入收藏
编程中的猫
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-10-1
收藏
 问题点数:0 回复次数:1 
求助:这个多项式相乘哪错了,它一个错误:in,syntax error at end of input

#include<stdio.h>
#include<stdlib.h>
struct list{
float coef;
int expn;
struct list *nextptr;
};

typedef struct list polynomial;
typedef polynomial *P;

void addC(P *,int ,int);
void creatpolyn(P *,P*);
void add(P *);
void print(P*);
void mutiply(P*,P*,P*);

main()
{
P a,b,c;
c=NULL;
// printf("");
creatpolyn(&a,&b);

print(&a); print(&b);
mutiply(&a,&b,&c);
print(&c);
}

void creatpolyn(P * aptr,P * bptr)
{

P * ahead, * bhead;
ahead= aptr;
bhead= bptr;
printf("please input polynomials a\n");
add( aptr);
printf("please input polynomials b\n");
add(bptr);
aptr=ahead;
bptr=bhead;


}

void add(P * ptr)
{
int coef1,expn1;
P newptr,ptr1;
while (1) {
newptr=(P)malloc(sizeof(P));
if (!newptr) {
newptr->nextptr=NULL;
printf("please input coef and expn,when expn=9999,exit\n");
scanf("%d%d",&coef1,&expn1);
if (expn1==9999)
break;
newptr->coef=coef1;
newptr->expn=expn1;
ptr1=*ptr; //不能直接调用ptr->nextptr;
ptr1->nextptr= newptr;
ptr1=ptr1->nextptr;
}
}
}

void mutiply(P *ap,P *bp,P *cp)
{
int expn1,coef1;
P ahead,bhead,ap1,bp1,cp1;
ahead= *ap;
bhead=*bp;
ap1=*ap;
bp1=*bp;
cp1=*cp;
while (ap1&&bp1) {
expn1=ap1->expn+bp1->expn;
coef1=(ap1->coef) *( bp1->coef);
addC(&cp1,expn1,coef1);
if (bp1)
bp1=bp1->nextptr;
else if ((!bp1)&&(!ap1)) {
ap1=ahead;
bp1=bhead;
}
else if (!bp1) {
bp1=bhead;
ap1=ap1->nextptr;
}
/* else if (bp1&&ap1) {
ap1=ahead;
bp1=bhead;
}

*/


/* if (ap)
cp->nextptr=bp;
else if (bp)
cp->nextptr=ap;
if (ap->expn>bp->expn)
bp=bp->nextptr;
else if (ap->expn<bp->expn)
ap=ap->nextptr;}}
*/
}

void addC(P * c,int expn2,int coef2)
{

P chead,newptr,pre,c1;
chead=*c;
c1=*c;
while (c1) {
pre=c1;
if (c1->expn==expn2)
c1->coef=coef2;
else c1=c1->nextptr;
}
c1=pre;

newptr=(P)malloc(sizeof(P));
if (!newptr) {
newptr->nextptr=NULL;
newptr->coef=coef2;
newptr->expn=expn2;
c1->nextptr=newptr;

}

}


搜索更多相关主题的帖子: syntax 多项式 input error end 
2006-10-05 23:24
Jackin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-8-22
收藏
得分:0 
输入语法错误,可能你的指针定义或使用的有问题。
我看这一句就很可疑:typedef polynomial *P;
是不是应该把*去掉?
2006-10-07 16:59
快速回复:求助:这个多项式相乘哪错了,它一个错误:in,syntax error at end of ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017195 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved