/
exercize_4_b.cpp
57 lines (42 loc) · 1 KB
/
exercize_4_b.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Scrivere un programma in linguaggio C che risolva il problema seguente.
Leggere un polinomio di grado n a coefficienti reali e valutarlo in un dato punto x.
*/
#include <iostream>
#define MAX_LEN 100
using namespace std;
int main(int argc, char *argv[])
{
float V[MAX_LEN];
float pot, f, x;
int i, n;
do
{
cout << "\ninserire il grado del polinomio, n = ";
cin >> n;
} while ((n <= 0) || (n >= MAX_LEN));
cout << "\ninserire i coeff. del pol. V_" << n << " … V_0: \n";
i = 0;
do
{
cin >> V[i];
i++;
} while (i <= n);
cout << "\nInserire il valore in cui valutare il polinomio, x = ";
cin >> x;
f = 0;
// Horner
for (i = 0; i <=n; i++) {
f = f*x + V[i];
}
cout << "\n f(" << x << ") = " << f << ".\n ";
// wait for user to hit enter or another key
std::cin.sync();
std::cout << "press enter to exit...";
std::cin.ignore();
//
// for Windows Users use
//
// system("pause");
return 0;
} // end main