I enter an array and the code should multiply this array by (x^2 + 2*A*X + A^A)
. for example an array 1, 3, 3, 1
should have answer 1, 5, 10, 10, 5, 1
if A = 1
. I have tried to write the code but I have no idea how I am supposed to multiply polynomials in C++.
CODE
#include "pch.h"
#include <iostream>
int main()
{
int a, n;
std::cout << "Enter the Power n: ";
std::cin >> n;
std::cout << "Enter the number A: ";
std::cin >> a;
int arr_size = n + 1;
int *array = new int[2 * arr_size];
std::cout << "Enter the array P(X): ";
for (int i = 0; i < arr_size; i++)
{
std::cin >> array[i];
}
for (int i = 0; i < arr_size; i++)
std::cout << array[i] << " ";
const int x = 1;
for (int i = 0; i < arr_size; i++) {
array[i] = array[i] * x ^ 2;
array[i] = array[i] * (2 * a*x);
array[i] = array[i] * (a * a);
std::cout << array[i] << " ";
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire