如何用C语言实现n元多项式乘法急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行.

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 09:17:46
如何用C语言实现n元多项式乘法急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行.
x[oGWH'zw1DDI{ .("%&$AB EPrG汳;Hdvo!~r=_{z^y^:bxPZg?Xްnq^;#++ʓXuҨ,+ΝJuqu5ح9<[:]%aO3Nu t;䛊 ұ o\>=81n2f67Ͽ84WG#OHeN~zӿ+y'分P/Y&$|ʩp)=/28QȘ#2oKv*т&YV!?eyŠOU/ R<`0L |:owg .Ke$xTꂄ)5B!G, Op*#G+Yes P,6`bdCA&"{yҾ1noN;SOL%DVky~u̟-s) γ1| t$A2K%<h.(h*]+gÃ_ֽ%:`F1gpx ڍh b­=3Y{(G  w1~>1$&.xOw%}07ܘrlz]cq΃%61՛|MrΚR]KpFr!QyDsADkU-aL9k(fX9gU-P K$J>ǣM[{lYA`G^bl!e`5d6? Q*N"JL^upUqhh`N>iU^PG!xbNA#*x&?p^sٜaI,QJKJ.% i:"̃Y.a*5\)iOj2LE%L+8Q.B5,#ܿB-@L\DE!p1w^(l>7c3Z0ϰZxY R Z))㋲4Q/7)s:ч&^AUX'̋hu֧R_$͟PT^{S}kҙNި^MWG5sooS@^ )>=K0 ~oc}g>F4 ri70r _d#Kvla8+԰M Œ[ >g|P|# p0b˘!B".E\4| itU0L_v8Q-)Z(6%A Jd XW~&W4/|C0Ȕ69nD;VI'&t<}90{^09K.9VHQfԓW5w?R!C!]lŒ}I'.`̴jPxࠑEH}}ґDqd6ӛqKHmcd;L_HDT<Rn) &~/2"7ʈjb7e'v):6mZH ?37IDAG Ԥŧ" a ^ղ]6MMƪe͐fΡ- vjjn1KJHmLxjBOX۷: p2d @,z_v7j1OA\ldԞXj}?=o,2i &BvO 8j}q[DU( Y~!֫7=}n*[0I8݂x% c g4lO ]+ ME&BCVX,B8$QS7#lv7Uvh/Φ£B[g7i6F ؞UWRg=rWUu-%qUݾ s{@BԦaupN܊vw弗KTPڻ?Ži*PI+$o ğAt_  QL!.[Q+斖HA[)nɥ(qŊa|Tz;d8 ٲ!$gkqT`+fN1%wxP:Q* 3}D['& }oCr4Ŀퟮۓ9Z=g><# 0nrMO1.HLw .?_N_`TUj8 !S˝s>Vm4yϜUX@`wI y-1So <Rب8 .*B .E#RI="ڟDCʀ>x;|d?!~ТC^Q5ZRI]|}g)Ȼf?Z 謹guvcU:.CK5? Bnms >E7)Zi9λ2 t8Tp*#IRn!|`~q{`G\A35?T^r~YvPZ8,$?{\9}-EO2 $3mm ҞhF)NO>"⢘;N2mZrt]^yz\vX[~~L]́E:x2@J `

如何用C语言实现n元多项式乘法急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行.
如何用C语言实现n元多项式乘法
急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行.

如何用C语言实现n元多项式乘法急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行.
/*
* 文件名: 1_3.c(选做题)
* 实验环境: Turbo C 2.0
* 完成时间: 2003年2月22日
*--------------------------------------------------------------------
* 改进说明: 可以实现多个多项式的加法、减法、乘法,并且比书中算法更加
* 合理. 例如: 连加a+b+c+d,连减a-b-c-d,连乘a*b*c*d.
*/
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define POSITIVE 1
#define NEGATIVE -1
typedef int status;
typedef struct NodeType
{
float fCoeff;
int iExpon;
struct NodeType *next;
} NodeType, *LinkType;
typedef LinkType polynomial;
typedef polynomial *PolyPointer;
status MakePolyBuff(PolyPointer *, const int);
status MakeNode(polynomial *, const float, const int);
void AppNodeToList(polynomial *, polynomial); /* 在链表尾追加结点 */
status CreatePolyn(PolyPointer, int);
status ProcStrError(const char[]); /* 检查输入的数据 */
void SortPolyn(PolyPointer, int); /* 根据iExpon域对链表进行升序排序 */
void DestroyBuff(PolyPointer, const int);
void DestroyPolyn(polynomial);
int PolynLength(const polynomial); /* 求链表的长度 */
void AddProcess(PolyPointer, const int, PolyPointer, const int);
void SubstractProcess(PolyPointer, const int, PolyPointer);
void MultiplyProcess(PolyPointer, const int, PolyPointer);
void PrintPolyn(const polynomial);
void MergePolynCoeff(PolyPointer, int); /* 在有序链表中,合并同类项 */
int main(void)
{
int iCounter,
iPolyNum; /* 多项式链表缓冲区中链表的个数 */
PolyPointer PolyBuff = NULL; /* 用户输入的多项式链表缓冲区 */
polynomial PolyAddRes = NULL, /* 存放连加结果链表 */
PolySubRes = NULL, /* 存放连减结果链表 */
PolyMulRes = NULL; /* 存放连乘结果链表 */
char strNum[10];
do
{
printf("请输入需要构造多项式的个数,至少2个: ");
gets(strNum);
iPolyNum = atoi(strNum);
} while (iPolyNum < 2);
MakePolyBuff(&PolyBuff, iPolyNum);
CreatePolyn(PolyBuff, iPolyNum);
SortPolyn(PolyBuff, iPolyNum);
MergePolynCoeff(PolyBuff, iPolyNum);
printf("\n打印用户输入并整合后的多项式:\n");
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
{
printf("第%d个项式:\n", iCounter + 1);
PrintPolyn(*(PolyBuff + iCounter));
}
AddProcess(PolyBuff, iPolyNum, &PolyAddRes, POSITIVE);
printf("\n----------------连加结果-----------------\n");
PrintPolyn(PolyAddRes);
SubstractProcess(PolyBuff, iPolyNum, &PolySubRes);
printf("\n----------------连减结果-----------------\n");
PrintPolyn(PolySubRes);
MultiplyProcess(PolyBuff, iPolyNum, &PolyMulRes);
printf("\n----------------连乘结果-----------------\n");
PrintPolyn(PolyMulRes);
printf("\n运行完毕!\n");
/* 回收资源 */
DestroyBuff(PolyBuff, iPolyNum);
DestroyPolyn(PolyAddRes);
DestroyPolyn(PolySubRes);
DestroyPolyn(PolyMulRes);
getch();
return 0;
}
status MakePolyBuff(PolyPointer *polyBuffHead, const int iPolyNum)
{
int iCounter;
*polyBuffHead = (PolyPointer)
malloc(sizeof(polynomial) * iPolyNum);
if (!(*polyBuffHead))
{
printf("错误,内存溢出!\n");
return FALSE;
}
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
*(*polyBuffHead + iCounter) = NULL;
return TRUE;
}
status CreatePolyn(PolyPointer PolyBuff, int iPolyNum)
{
int iCounter, iExpon;
float fCoeff;
char strNum[100], strTemp[64], *cpCurr, *cpCurrNum;
polynomial pNewNode = NULL, pInsPos = NULL;
printf("\n请输入构造多项式的系数和指数...\n");
printf("输入一个多项式的方式为: 系数, 指数; ... ; 系数, 指数;\n例如: 3, 4; 5, 6; 7, 8;\n");
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
{
printf("\n请输入第%d个多项式:\n", iCounter + 1);
gets(strNum);
if(!ProcStrError(strNum)) return FALSE;
cpCurr = cpCurrNum = strNum;
while (*cpCurr != '\0')
{
if (*cpCurr == ',')
{
strncpy(strTemp, cpCurrNum, cpCurr - cpCurrNum);
strTemp[cpCurr - cpCurrNum] = '\0';
fCoeff = (float)atof(strTemp);
cpCurrNum = cpCurr + 1;
}
else if (*cpCurr == ';')
{
strncpy(strTemp, cpCurrNum, cpCurr - cpCurrNum);
strTemp[cpCurr - cpCurrNum] = '\0';
iExpon = atoi(strTemp);
MakeNode(&pNewNode, fCoeff, iExpon);
AppNodeToList(PolyBuff + iCounter, pNewNode);
cpCurrNum = cpCurr + 1;
}
cpCurr++;
}
}
return TRUE;
}
status MakeNode(LinkType *pp, const float coeff, const int expon)
{
if (!(*pp = (LinkType)malloc(sizeof(NodeType) * 1)))
{
printf("Error, the memory is overflow!\n");
return FALSE;
}
(*pp)->fCoeff = coeff;
(*pp)->iExpon = expon;
(*pp)->next = NULL;
return TRUE;
}
void AppNodeToList(polynomial *pHead, polynomial pNewNode)
{
static polynomial pCurrNode;
if (!(*pHead))
(*pHead) = pCurrNode = pNewNode;
else
{
pCurrNode->next = pNewNode;
pCurrNode = pCurrNode->next;
}
}
void SortPolyn(PolyPointer PolyBuff, int iPolyNum)
{
int iCounter;
polynomial pTemp, pTempCurrNode, /* 临时链表 */
pPrevMinExp, pCurrMinExp,/* 指向最小iExpon结点的指针 */
pCurrNode, pPrevNode;
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
{
pTemp = NULL;
while (*(PolyBuff + iCounter) != NULL)
{
pPrevNode = pPrevMinExp = pCurrMinExp =
*(PolyBuff + iCounter);
pCurrNode = (*(PolyBuff + iCounter))->next;
while (pCurrNode != NULL)
{
if (pCurrMinExp->iExpon > pCurrNode->iExpon)
{
pPrevMinExp = pPrevNode;
pCurrMinExp = pCurrNode;
}
pPrevNode = pCurrNode;
pCurrNode = pCurrNode->next;
}
/* 将系数最小的结点从原链表中取出 */
if (pCurrMinExp == *(PolyBuff + iCounter))
*(PolyBuff + iCounter) = pPrevMinExp->next;
else
pPrevMinExp->next = pCurrMinExp->next;
/* 将系数最小的结点插入升序链表 */
pCurrMinExp->next = NULL;
if (!pTemp)
pTemp = pTempCurrNode = pCurrMinExp;
else
{
pTempCurrNode->next = pCurrMinExp;
pTempCurrNode = pTempCurrNode->next;
}
}
*(PolyBuff + iCounter) = pTemp;
}
}
void MergePolynCoeff(PolyPointer PolyBuff, int iPolyNum)
{
int iCounter;
float MergeCoeffRes = 0;
polynomial TempList, ResList = NULL, pCurrNode, pPreNode,
pNewNode = NULL;
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
{
pPreNode = TempList= *(PolyBuff + iCounter);
MergeCoeffRes = pPreNode->fCoeff;
pCurrNode = (*(PolyBuff + iCounter))->next;
while (pCurrNode != NULL)
{
while ((pCurrNode != NULL) &&
(pCurrNode->iExpon == pPreNode->iExpon))
{
MergeCoeffRes += pCurrNode->fCoeff;
pPreNode = pCurrNode;
pCurrNode = pCurrNode->next;
}
/* 在ResList中加入新结点 */
if (MergeCoeffRes != 0)
{
MakeNode(&pNewNode, MergeCoeffRes, pPreNode->iExpon);
AppNodeToList(&ResList, pNewNode);
MergeCoeffRes = 0;
}
pPreNode = pCurrNode;
}
DestroyPolyn(TempList);
*(PolyBuff + iCounter) = ResList;
ResList = NULL;
}
}
void AddProcess(PolyPointer polyBuff, const int iPolyNum,
PolyPointer pResult, const int iSign)
{
int iCounter;
float fCoeffRes;
polynomial pNewNode, pCurrNode_1, pCurrNode_2,
pDelList = NULL, /* 下次要删除的中间结果链表 */
pResList = NULL; /* 中间结果链表 */

pCurrNode_1 = *(polyBuff);
for (iCounter = 1; iCounter < iPolyNum; iCounter++)
{
pCurrNode_2 = *(polyBuff + iCounter);
while (pCurrNode_1 != NULL && pCurrNode_2 != NULL)
{
if (pCurrNode_1->iExpon == pCurrNode_2->iExpon)
{
fCoeffRes = 0;
fCoeffRes = pCurrNode_1->fCoeff +
iSign * pCurrNode_2->fCoeff;
if (fCoeffRes != 0)
{
MakeNode(&pNewNode, fCoeffRes,
pCurrNode_1->iExpon);
AppNodeToList(&pResList, pNewNode);
}
pCurrNode_1 = pCurrNode_1->next;
pCurrNode_2 = pCurrNode_2->next;
}
else if (pCurrNode_1->iExpon < pCurrNode_2->iExpon)
{
MakeNode(&pNewNode, pCurrNode_1->fCoeff,
pCurrNode_1->iExpon);
AppNodeToList(&pResList, pNewNode);
pCurrNode_1 = pCurrNode_1->next;
}
else /* 当pCurrNode_1->iExpon > pCurrNode_2->iExpon时候 */
{
MakeNode(&pNewNode, iSign * pCurrNode_2->fCoeff,
pCurrNode_2->iExpon);
AppNodeToList(&pResList, pNewNode);
pCurrNode_2 = pCurrNode_2->next;
}
}
/* 加入余下的多项式 */
while (pCurrNode_1 != NULL)
{
MakeNode(&pNewNode, pCurrNode_1->fCoeff,
pCurrNode_1->iExpon);
AppNodeToList(&pResList, pNewNode);
pCurrNode_1 = pCurrNode_1->next;
}
while (pCurrNode_2 != NULL)
{
MakeNode(&pNewNode, iSign * pCurrNode_2->fCoeff,
pCurrNode_2->iExpon);
AppNodeToList(&pResList, pNewNode);
pCurrNode_2 = pCurrNode_2->next;
}
if (pDelList != NULL) DestroyPolyn(pDelList);
pCurrNode_1 = pResList;
pDelList = pResList;
pResList = NULL;
}
*pResult = pCurrNode_1;
}
void SubstractProcess(PolyPointer polyBuff, const int iPolyNum,
PolyPointer pResult)
{
AddProcess(polyBuff, iPolyNum, pResult , NEGATIVE);
}
void MultiplyProcess(PolyPointer polyBuff, const int iPolyNum,
PolyPointer pResult)
{
int iCounter = 1, jCounter = 0, iLength; /* 缓冲区的长度 */
PolyPointer pTemPBuff = NULL; /* 存放中间结果的缓冲区 */
polynomial pCurrNode_1, pCurrNode_2, pNewNode = NULL;
/* 初始化 */
pCurrNode_1 = polyBuff[0];
iLength = PolynLength(polyBuff[0]);
MakePolyBuff(&pTempBuff, iLength);
while (TRUE)
{
while (pCurrNode_1 != NULL)
{
pCurrNode_2 = polyBuff[iCounter];
while (pCurrNode_2 != NULL)
{
MakeNode(&pNewNode,
pCurrNode_1->fCoeff * pCurrNode_2->fCoeff,
pCurrNode_1->iExpon + pCurrNode_2->iExpon);
AppNodeToList(&pTempBuff[jCounter], pNewNode);
pCurrNode_2 = pCurrNode_2->next;
}
jCounter++;
pCurrNode_1 = pCurrNode_1->next;
}
/* 回收旧的中间结果 */
if (pResult != NULL) DestroyPolyn(*pResult);
/* 获得新的中间结果 */
AddProcess(pTempBuff, iLength, pResult , POSITIVE);
DestroyBuff(pTempBuff, iLength); /* 回收存中间结果的缓冲区 */
jCounter = 0;
if (++iCounter >= iPolyNum)
break;
else
{
iLength = PolynLength(*pResult);
MakePolyBuff(&pTempBuff, iLength);
pCurrNode_1 = *pResult;
}
}
}
void PrintPolyn(const polynomial polyList)
{
polynomial pCurrNode = polyList;
printf("多项式的长度为: %d\n", PolynLength(polyList));
while (pCurrNode != NULL)
{
printf("%.2fX^%d", pCurrNode->fCoeff, pCurrNode->iExpon);
if (pCurrNode->next != NULL)
if (pCurrNode->next->fCoeff > 0 )
printf("+");
pCurrNode = pCurrNode->next;
}
printf("\n");
}
int PolynLength(const polynomial polyList)
{
int iLength = 0;
polynomial pCurrNode = polyList;

while (pCurrNode != NULL)
{
pCurrNode = pCurrNode->next;
iLength++;
}
return iLength;
}
void DestroyBuff(PolyPointer polyBuff, const int iPolyNum)
{
int iCounter;
for (iCounter = 0; iCounter < iPolyNum; iCounter++)
DestroyPolyn(polyBuff[iCounter]);
free(polyBuff);
}
void DestroyPolyn(polynomial polyList)
{
polynomial pCurrNode;
while (polyList != NULL)
{
pCurrNode = polyList;
polyList = polyList->next;
free(pCurrNode);
}
}
status ProcStrError(const char str[])
{
const char *cpCurr = str;
if (!strlen(str))
{
printf("你没有输入数据!\n");
return FALSE;
}
while (*cpCurr != '\0')
{
if (!(*cpCurr == ' ' || *cpCurr == ',' || *cpCurr == ';'
|| *cpCurr == '-')
&& ('0' > *cpCurr || *cpCurr > '9')
|| (*(cpCurr + 1) == '\0' && *cpCurr != ';'))
{
printf("输入数据出错,请注意正确的输入方式!\n");
return FALSE;
}
cpCurr++;
}
return TRUE;
}

如何用C语言实现n元多项式乘法急求详细代码,最好是两个三元二次多项式的乘法的详细代码,急啊,提前向各位大侠道谢了!C语言的,要能运行. 如何用C语言实现2的n次方 如何用C语言实现多项式的加法和乘法给定两个多项式,用程序实现这两个多项式的相加和相乘.要求多项式的系数只能取1或者0;同时满足1+1=0;例如给定多项式(1+X)*(1+X)=X2.基本要求:(1)实 如何用C语言实现一元多项式简单计算器的设计〔问题描述〕输入并建立两个多项式并输出多项式设计一个程序:对两个多项式进行加、减法及乘法运算,建立一个新多项式并输出.或设计一个 如何用C语言实现两个一元多项式的相加和相乘?就是说,加法时如何将它们的同类项相加,乘法时将每一项都与另一个一元多项式相乘.用C语言描述出来,如果可以麻烦将程序大致描述一下. 关于C语言的问题:如何用C语言实现n阶行列式和矩阵的值 请问如何用C语言实现汉字和Unicode编码的转换 求程序 如何用C语言编写程序实现哥德巴赫猜想 如何用C语言实现NFA向DFA的转换 乘法原理如何用集合语言表述? 如何用C语言求最小公倍数. 如何用java二维数组实现矩阵的乘法 如何用C++实现矩阵加法和乘法 请问如何用C语言实现下面的迭代和递归的两种算法Given a list of N integers,denoted by A0,A1,…,AN – 1,there are two methods to print them in the given order.The iterative method is very simple:just print the integers one by one 如何用C语言求s=1/1*2+1/2*3+.+1/n(n+1) 如何用简单的C语言实现带有括号的四则运算 偶数阶的阵列可以组成魔方阵吗,有的话如何用C语言实现? matlab里面的函数wden如何用C语言实现啊?需要具体的算法~