Computation of nth-degree of Bernstein polynomials

AllBernstein.cpp

//============================================================================
// Name        : AllBernstein.cpp
// Author      : chd
// Version     :
// Copyright   : Your copyright notice
// Description : Calculates the value of Bernstein polynomials of degree n, C++ Ansi-style
//============================================================================

#include <iostream>
#include "AllBernstein.h"
using namespace std;

double* AllBernstein(int n, double u){

	double *B=new double [n+1];
	B[0]=1.0;
	double u1=1-u;
	double saved,tmp;

	for (int j = 1; j <= n; ++j) {
		saved=0;
		for (int i = 0; i < j; ++i) {
			tmp=B[i];
			B[i]=saved+u1*tmp;
			saved=u*tmp;
		}

		B[j]=saved;

	}
	return B;
}


void print(int n, double u, double* B){

	cout<<"Bi"<<n<<"("<<u<<")"<<endl;
	for (int i = 0; i < n+1; ++i) {
		cout<<B[i]<<endl;
	}

}

AllBernstein.h

/*
 * AllBernstein.h
 *
 *  Created on: Mar 13, 2016
 *      Author: christos
 */

#ifndef ALLBERNSTEIN_H_
#define ALLBERNSTEIN_H_


double* AllBernstein(int n, double u);
void print(int n, double u, double* B);


#endif /* ALLBERNSTEIN_H_ */

main.cpp

/*
 * main.cpp
 *
 *  Created on: Mar 13, 2016
 *      Author: christos
 */


#include "AllBernstein.h"


int main() {

	double u;
	int n;

	n=2;
	u=0.5;
	double* arrBernstein=AllBernstein(n,u);
	print(n,u,arrBernstein);

}