0

C でプログラムを作成する必要があり、それによって 2 つの単一変数多項式を追加する必要があります。私は部分的にそれを行うことができ、間違った答えになってしまいます。

次の 2 つの多項式を考えてみましょう。

5x^2 + 6x^3 + 9  
6x^3 + 5x^2 + 3x + 2  

手動で答えがどうなるかはわかっています。ここに私の論理があります:

if(term1->exp == term2->exp){ // same power of x
    // add them, store them in the final answer linked list
    // increment pointers of both the term1 and term2 linkedlist
}
if(term1->exp > term2->exp){ // term1 has higher power of x than term2
    // increment term1 linked list in search of lower power of x
    // ** term1 is now pending **
}

if(term1->exp < term2->exp){ // term1 has lesser power of x than term2
    // increment term2 linked list in search of lower power of x
    // ** term2 is now pending **
}  

私が直面している問題は、保留中の条件にあります。保留中の条件を処理するにはどうすればよいですか?
それらを適切に追加するにはどうすればよいですか?

コードはこちら: http://pastebin.com/70UJdNiQ

4

2 に答える 2