(C++)多项式加减法(一元)

(easy)一元多项式表示

#include 
#include
using namespace std;
 
struct node{
	int coef;           //系数 
	int expo;           //指数 
	node *next;
};
int main()
{
	cout<<"几项呀?  \n";
	int n;  cin>>n;
	node *now,*pre;
	node *head = new node;
	pre=head;
	
	for(int i=1;i<=n;i++)      //录入 
	{   int a,b; 
		cout<<"第"<>a;    cout<>b;    cout<coef=a;
		now->expo=b;
		pre->next=now;
		pre=now;
	}
	
	cout<<"输出表达式... \n";  
	pre=head;   
	for(int i=1;i<=n;i++)
	{
		pre=pre->next;
		if(pre->expo==0)  cout<coef;
		else cout<coef<<"x^"<expo;
		if(pre->next->coef>0&&i!=n)    cout<<"+";
    }  cout<>x;  cout<<"收到\n";
    cout<<"计算表达式...  \n";  
    int num=0;
    pre=head;   
	for(int i=1;i<=n;i++)
	{
		pre=pre->next;
		num+=pre->coef*pow(x,pre->expo);
	}
	cout<<"值是:"<

 

(C++)多项式加减法(一元)_第1张图片

 

(hard)(读入不是太会,不想写)

题33:二元多项式基本运算

选择合适的存储结构表示二元多项式,并实现基本的加减运算

要求:

1)二元多项式的输入采用如下方式进行键盘输入

(5y^2+7)x^4 + (3y^4+2y+9)x^2 + (2y^2+y)x + (y+9)。

2)按照键盘输入的方式进行结果输出。

3)要求输出结果的升幂和降幂两种排列情况

这题找这位学长吧,他的课设

https://blog.csdn.net/kyl666/article/details/75158223

你可能感兴趣的:(课程设计&实验&代码&报告)