⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commfactor.cpp

📁 常用算法与数据结构原代码
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -