nullzeros.cpp

来自「This library defines basic operation on 」· C++ 代码 · 共 31 行

CPP
31
字号
// nullzeros.cpp : Demonstrates use of removeNullZeros
//
#include <iostream>
#include "polyzero.h"

using namespace std;

void main() {
    //  this example shows how to remove null roots from a polynomial
    //  using removeNullRoots()

    //  create polynomial p(x)=x^3+x^2 (= x*x*(x+1))
    Polynomial<float> p(3, 0.f, 0.f, 1.f, 1.f);

    // print
    cout << "before deflating P(x)=";
    for (int i = p.degree(); i >= 1; --i)
        cout << p[i] << "*x^" << i << "+";
    cout << p[0] << endl << endl;
        
    int n = removeNullZeros(p);

    cout << "removeNullZeros() removed " << n << " zeros" << endl;

    // print modified polynomial
    cout << "after deflating P(x)=";
    for (int i = p.degree(); i >= 1; --i)
        cout << p[i] << "*x^" << i << "+";
    cout << p[0] << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?