Advertisement
obernardovieira

AM2 1º desafio [Mathematica Challenge]

Feb 19th, 2015
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. int main(void) {
  8.  
  9.     int n, x0, p;
  10.     int *a;
  11.  
  12.     cout << "Qual o grau do polimonio? ";
  13.     cin >> n;
  14.     a = new int[n + 1];
  15.  
  16.     for (int v = n; v != -1; v--) {
  17.         cout << "Introduza um valor para o 'a' na ordem #" << v << " :";
  18.         cin >> a[v];
  19.     }
  20.  
  21.     cout << "Qual o valor de x? ";
  22.     cin >> x0;
  23.     p = a[n];
  24.  
  25.     for (int z = n - 1; z != -1; z--)
  26.         p = p * x0 + a[z];
  27.  
  28.     cout << "O resultado é " << p << endl;
  29.  
  30.     return 1;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement