Alx09

Topa Andreea

Dec 5th, 2021
653
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void CitireCoef(int *v, int n){
  6.   ++n;
  7.   for( int i = 0; i < n; ++i){
  8.     cout << "Introduceti coeficentul a"<< i <<": "; cin >> v[i];
  9.   }
  10. }
  11.  
  12. double CalcPolinom(int *v, int n, double punctDat){
  13.     double x = 1, valCautata = 0;
  14.     ++n;
  15.     for(int i = 1; i < n; ++i) x *= punctDat;
  16.     while(n){
  17.         valCautata += v[--n] * x;
  18.         x /= punctDat;
  19.     }
  20.  
  21.     return valCautata;
  22. }
  23.  
  24. int main()
  25. {
  26.     int v[7], n;
  27.     double punctDat;
  28.     do{
  29.     cout << "Coefecient polinom: "; cin >> n;
  30.     if(n < 2 || n > 6) cout <<" Gradul a fost introdus incorect \n";
  31.     }while (n < 2 || n > 6);
  32.     CitireCoef(v, n);
  33.     cout << "Punctul in care se calculeaza: "; cin >> punctDat;
  34.     cout <<"Valoare polinomului in punctul " << punctDat << " este " << CalcPolinom(v, n, punctDat);
  35.     return 0;
  36. }
  37.  
RAW Paste Data