Created
March 8, 2015 05:43
-
-
Save Aracturat/42beefd7399aca299a57 to your computer and use it in GitHub Desktop.
new Polynom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
double polynom(double x, double a[], int n) | |
{ | |
double p_val = 0; // p_val не очень говорящее название переменной. Лучше написать что-то типа sum | |
for (int j = 0; j <= n; j++) | |
{ | |
p_val = p_val + a[j] * pow(x,j); | |
} | |
return p_val; | |
} | |
void main() | |
{ | |
const int n = 3; | |
double a[n+1]; | |
for (int i = 0; i <= n; i++) | |
{ | |
cin >> a[i]; | |
} | |
double p_val = polynom(2, a, n); // Здесь лучше писать не 3, а 3.0 потому что так будет лучше с точностью. | |
cout << p_val << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment