分类：电脑/网络-程序设计-C/C++
问题：急急！高手帮忙！这题错在哪里?C语言的这题已经编译通过了,但是得 
这题已经通过了,但是得出来的结果不对.例如:a(x)=3x^2+2x,b(x)=6x^2+1结果是:9x^9+3x^9+0.00x^0#include<stdio.h>voidmain(){typedefstructploy_node*poly_ptr;structpoly_node{floatcoef;intexpon;poly_ptrnext;};poly_ptrhead1,head2,head3;poly_ptrprevious1,previous2,previous3;poly_ptrcurrent1,current2,curr这题已经通过了,但是得出来的结果不对.例如:a(x)=3x^2+2x,b(x)=6x^2+1结果是:9x^9+3x^9+0.00x^0#include<stdio.h>voidmain(){typedefstructploy_node*poly_ptr;structpoly_node{floatcoef;intexpon;poly_ptrnext;};poly_ptrhead1,head2,head3;poly_ptrprevious1,previous2,previous3;poly_ptrcurrent1,current2,current3;poly_ptra,b,c,d;floatcoef1,coef2,coef3;intexpon1,expon2,expon3;head1=(poly_ptr)malloc(sizeof(poly_ptr));/*setaheadnodeforpolynomial1*/previous1=head1;head2=(poly_ptr)malloc(sizeof(poly_ptr));/*setaheadnodeforpolynomial2*/previous2=head2;head3=(poly_ptr)malloc(sizeof(poly_ptr));/*setaheadnodeforpolynomial3*/previous3=head3;printf("\n**************************AddingPolynomials******************************\n");printf("\n---- !!!----");printf("\nAndwhenthecoefficientandexponentare0,thenthesystemwillexit.");printf("\n----------------------------------------------------------------------------\n");printf("\nEnterthecoefficientandexponentofthepolynomial1:\n");scanf("%f",&coef1);scanf("%d",&expon1);while(coef1!=0){current1=(poly_ptr)malloc(sizeof(poly_ptr));current1->coef=coef1;current1->expon=expon1;previous1->next=current1;/*linkthelistprevious1andlistcurrent1*/previous1=current1;printf("\Enterthecoefficientandexponentofthepolynomial1:\n");scanf("%f",&coef1);scanf("%d",&expon1);}previous1->next=NULL;head1=head1->next;/*deletetheheadnode*/printf("\Enterthecoefficientandexponentofthepolynomial2:\n");scanf("%f",&coef2);scanf("%d",&expon2);while(coef2!=0){current2=(poly_ptr)malloc(sizeof(poly_ptr));current2->coef=coef2;current2->expon=expon2;previous2->next=current2;/*linkthelistprevious2andlistcurrent2*/previous2=current2;printf("\Enterthecoefficientandexponentofthepolynomial2:\n");scanf("%f",&coef2);scanf("%d",&expon2);}previous2->next=NULL;head2=head2->next;/*deletetheheadnode*//*addpolynomial1andpolynomial2*/a=head1;b=head2;while(a!=NULL&&b!=NULL){if(a->expon==b->expon)/*iftheexponentsoftwonodesarethesame,thenaddthetwocoefficientandsetanewnode*/{coef3=a->coef+b->coef;expon3=a->expon;if(coef3!=0){current3=(poly_ptr)malloc(sizeof(poly_ptr));current3->coef=coef3;current3->expon=expon3;previous3->next=current3;previous3=current3;}a=a->next;b=b->next;}else/*iftheexponentsarenotthesame,thencopythebiggernodetothepoly3*/{if(a->expon<b->expon){current3=(poly_ptr)malloc(sizeof(poly_ptr));current3->coef=b->coef;current3->expon=b->expon;previous3->next=current3;previous3=current3;b=b->next;}else{current3=(poly_ptr)malloc(sizeof(poly_ptr));current3->coef=a->coef;current3->expon=a->expon;previous3->next=current3;previous3=current3;a=a->next;}}}while(a!=NULL)/*copytheothersnodesofpoly1toploy3*/{current3=(poly_ptr)malloc(sizeof(poly_ptr));current3->coef=a->coef;current3->expon=a->expon;previous3->next=current3;previous3=current3;a=a->next;}while(b!=NULL)/*copytheothersnodesofpoly2toploy3*/{current3=(poly_ptr)malloc(sizeof(poly_ptr));/*copyanode*/current3->coef=b->coef;current3->expon=b->expon;previous3->next=current3;previous3=current3;b=b->next;}previous3->next=NULL;/*setthelastnodebeNULL*/current3=head3;/*deletetheheadnode*/head3=head3->next;free(current3);c=head3;printf("\nThepolynomial3is:");while(c!=NULL){printf("%.2fx^",c->coef);printf("%d+",c->expon);c=c->next;}printf("\nEnteranykeytoexit......");getch();}
回答：如果要 exponent 那你前面要加 #include<cmath>

#include<iostream>
#include<cmath>
using n#include<stdio.h> 
amespace std;