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

#include<stdio.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;
while (1) {
newptr=(P)mallac(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;
ptr->nextptr= newptr;
* ptr=ptr->nextptr;
}
}
}

void mutiply(P *ap,P *bp,P *cp)
{
P ahead,bhead;
ahead=ap;
bhead=bp;

while (1) {
addC(P *cp,ap->expn+bp->expn,ap->coef * bp->coef);
if (bp)
bp=bp->nextptr;
else {
bp=bhead;
ap=ap->nextptr;
}
else if (bp&&ap) {
ap=ahead;
bp=bhead;}

break;


}

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

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

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

}

}

//它总是同一个错误,应该是语法问题,我是在dev-c的环境下编的。 谢谢

搜索更多相关主题的帖子: 相乘 多项式 
2006-10-01 22:52
快速回复:求助:这个多项式相乘哪错了,谢谢
数据加载中...
 
   



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

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