Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise11.cpp
blob: a906855e35e4b609a25e610b171ffb8c4544257f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>

int main() {
	unsigned int n;
	std::cin >> n;

	double* coeffs = new double[n + 1];
	for (unsigned int i = 0; i < n + 1; i++)
		std::cin >> coeffs[i];

	double potentialRoot;
	std::cin >> potentialRoot;

	double sum = 0.0, toPower = 1.0;
	for (unsigned int i = n + 1; i > 0; i--) {
		sum += coeffs[i-1] * toPower;
		toPower *= potentialRoot;
	}

	const double ZERO_BORDER = 0.00001;

	if (-ZERO_BORDER < sum && sum < ZERO_BORDER) {
		std::cout << "Is a root" << std::endl;
	}
	else {
		std::cout << "Not a root" << std::endl;
	}

	delete[] coeffs;

	return 0;
}