与C语言有关的专业问题,c语言有关问题

当前位置:我的异常网» C语言 » c语言有关问题

c语言有关问题

www.myexceptions.net  网友分享于:2013-03-17  浏览:5次

c语言问题

多项式相加:

#   include   "stdlib.h "

#   include   "stdio.h "

struct   list

{   int   coef;

int   exp;

struct   list   *next;

};

typedef   struct   list   node;

void   main()

{   node   *ptr1,*ptr2;

node   *creatlist(node   *ptr1);

node   *creatlist(node   *ptr2);

node   *order(ptr1);

node   *order(ptr2);

node   *addpoly(node   *ptr1,node   *ptr2);

ptr1=creatlist(ptr1);

ptr2=creatlist(ptr2);

ptr1=order(ptr1);

ptr2=order(ptr2);

view(ptr1);

view(ptr2);

ptr1=addpoly(ptr1,ptr2);

view(ptr1);

}

node   *order(node   *pre)

{   node   *p=pre,*q,*l;

int   j,i=0,n;

q=(node   *)malloc(sizeof(node));

while(p-> next!=NULL)

{   i++;

p=p-> next;

}

for(j=0;j

{   p=pre-> next;

for(n=1;n <=i-j;n++)

{   l=p-> next;

if((p-> exp) exp))

{   q-> exp=p-> exp;q-> coef=p-> coef;

p-> exp=l-> exp;p-> coef=l-> coef;

l-> exp=q-> exp;l-> coef=q-> coef;

}

p=p-> next;

}       free(q);

}

return(pre);

}

node   *creatlist(node   *ptr)

{   node   *r,*s;

int   num,i,n,m;

ptr=(node   *)malloc(sizeof(node));

ptr-> next=NULL;

r=ptr;

printf( "please   in   put   the   length   of   the   list   you   want   to   creat:\n ");

scanf( "%d ",&n);

printf( "please   input   %d   pairs   numbers==> \n ",n);

for(i=0;i

{   s=(node   *)malloc(sizeof(node));

scanf( "%d%d ",&num,&m);

s-> coef=num;

s-> exp=m;

r-> next=s;

r=s;

}

r-> next=NULL;

return(ptr);

}

view(node   *ptr)

{   node   *p;

p=ptr-> next;

printf( "The   poly   is   ==> \n ");

while(p!=NULL)

{

printf( "%dx^%d     ",p-> coef,p-> exp);

p=p-> next;

}printf( "\n ");

}

node   *addpoly(node   *ptr1,node   *ptr2)

{   node   *p,*q,*r,*s,*pre;

p=ptr1-> next;

q=ptr2-> next;

pre=(node   *)malloc(sizeof(node));

pre-> next=NULL;

r=pre;

文章评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值