commfactor.cpp
来自「常用算法与数据结构原代码」· C++ 代码 · 共 55 行
CPP
55 行
#include <iostream.h>
#include <math.h>
#define EPS 1e-6
int Remainder(double *pA,int an,double *pB,int bn,double *&q)
{
double x,y,*temp;
int k,j;
if (an<bn)
{
temp=pA;pA=pB;pB=temp;
k=an;an=bn;bn=k;
}
while (1)
{
while (*pB==0.0 && bn>0)
{
bn--;
pB++;
}
if (*pB==0.0 && bn==0)
break;
k=0;x=*pB;
while (k<=bn)
pB[k++]/=x;
for (k=0;k<=an-bn;k++)
{
x=pA[k];
for (j=0;j<bn;j++)
{
y=pA[k+j+1]-x*pB[j+1];
pA[k+j+1]=(fabs(y)<EPS) ? 0.0 : y;
}
}
temp=pA;
pA=pB;
pB=temp+an-bn+1;
an=bn--;
}
q=pA;
return an;
}
void main()
{
double pA[]={2,1,2,1,0,0};
double pB[]={1,0,1};
int an=5,bn=2;
double *q;
int i,t;
t=Remainder(pA,an,pB,bn,q);
for (i=0;i<=t;i++)
cout<<q[i]<<" ";
cout<<endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?