大家来找茬吧,很多错误,请教您,谢谢
一个多项式加法问题,我先赋值,然后使用函数Padd求的和,1 #include<stdio.h>
2 #define MAX_SIZE 100
3
4 void main()
5 {
6
7 struct polynomail{
8 float coef;/*值*/
9 int expon;//指数
10 };
11
12 int i = 0;
13 struct polynomail *avail;
14 int padd(int starta,int finisha,int startb,int finishb,struct polynomail *avail,struct polymail *terms);
15
16 struct polynomail terms[MAX_SIZE];
17
18 int starta = 0,finisha = 1;
19 int startb = 2,finishb = 5;
20 terms[starta] = {2,1000};
21 terms[finisha] = {1,0};
22 terms[startb] = {1,4};
23 terms[startb + 1] = {10,3};
24 terms[startb + 2] = {3,2};
25 terms[startb + 3] = {1,0};
26
27 for(i=0;i<=startb;i++)
28 {
29 printf("[%f,%d] ",terms[i].coef,terms[i].expon);
30 printf("\n");
31 }
32
33 avail = &terms[finishb+1];
34 padd(starta,finisha,startb,finishb,avail,terms);
35
36 }
37
38 int padd(int starta,int finisha,int startb,int finishb,struct polynomail *avail,struct polynomail *terms)
39 {
40 struct polynomail *print=avail;
41 while( starta <= finishb && startb <= finishb && avail<=terms+MAX_SIZE)
42 {
43 switch (COMPARE(terms[starta].expon,terms[startb].expon))
44 { case 1 :
45 avail->coef=terms[starta].coef;
46 avail->expon=terms[starta].expon;
47 starta++;
48 break;
49 case 0 :
50 avail->coef=terms[starta].coef+terms[startb].coef;
51 avail->expom=terms[starta].expon;
52 starta++;
53 startb++;
54 break;;
55 case -1:
56
57 avail->coef=terms[startb].coef;
58 avail->expon=terms[startb].expon;
59 startb++;
60 break;
61 }
62 avail++;
63 }
64 for (;print<avail;print++)
65 {
66 printf("[%f,%d]",print->coef,print->expon);
67 printf("\n");
68 }
69 }