c語言實現多項式的基本運算

2021-10-09 17:07:21 字數 2028 閱讀 9865

多項式是數學中常用的一種表示式,現在我們給出用c語言程式設計實現多項式的計算,並且多項式的計算是鍊錶的典型應用,通過程式設計實現多項式,也為我們鞏固一下鍊錶的知識以及它的生活應用。

下面給出**

#include

#include

#include

typedef

struct node

*polynode;

intlocateelem

(polynode l,

int e)

//在鍊錶中查詢與e相等的元素並返回元素位置

return0;

}int

createpoly

(polynode &l ,

int m)

} r->next=

null

;return1;

}void

print

(polynode l)

//列印函式

}void

addpoly

(polynode &la,polynode &lb)

//多項式相加

else

if(p->exp==q->exp)

else

p=pre->next;

r=q;

//刪除q節點前先賦給r

q=q->next;

free

(r);

//刪除q節點

lb->exp--

;//lb長度-1

}else

//如果lb指數項小,則插入到la中 }if

(q!=

null

)//鏈結p的剩餘節點

free

(lb);}

void

subtractpoly

(polynode &la,polynode &lb)

//多項式相減

else

if(p->exp==q->exp)

else

p=pre->next;

r=q;

//刪除q節點前先賦給r

q=q->next;

free

(r);

//刪除q節點

lb->exp--

;//lb長度-1

}else

//如果lb指數項小,則插入到la中 }if

(q!=

null

)//鏈結p的剩餘節點

la->exp+

=lb->exp;

//lalb長度相加

}free

(lb);}

polynode multiplypoly

(polynode la,polynode lb)

//多項式相乘

p=p->next;

while

(p)// 下面依次將元素插入到lc中

else

if(rear->exp==s->exp)

//如果係數相等,則相加

else

rear=pre->next;

break;}

else

//如果之前沒有,則插入 }if

((s!=

null)&&

(rear==

null))

//如果後面還有項,則補到lc後

q=q->next;

} p=p->next;

}return lc;

}void

substitution

(polynode l,

float x)

printf

("代入結果為:%f"

,sum);}

void

menu()

intmain()

return0;

}

請看執行結果

C語言實現一元多項式加法運算

說到一元多項式相加,相信很多小夥伴都不會陌生,甚至 合併同類項 已經要脫口而出了 因為上節課本人就是這樣的哈哈 回到正題,一元多項式的加法運算,大概是這樣的 知道怎麼操作了之後就來看看如何儲存一元多項式叭 很明顯為了方便操作,而且每一項都含有 係數 coefficient 指數 index 為了避免...

C語言實現一元多項式的基本操作

函式宣告 poly.h標頭檔案 一元多項式的鏈式表達,利用帶頭節點的單鏈表實現 多項式的插入和刪除操作是比較頻繁.用鏈式結構比順序結構更好 鍊錶按照指數公升序排列 typedef struct term 存放係數和指數的數對 typedef struct pnode pnode,poly poly ...

C語言實現 一元多項式運算器

程式簡介 功能 對多項式求值,求導,兩多項式相加,相減,相乘等運算 include include includetypedef struct nodetypenodetype nodetype creatlist 建立乙個人鍊錶,用來存放乙個多項式,返回乙個頭指標 void printlist n...