I have a problem with the following statement:
Given a vector A with n real numbers, get another vector B, also with n real numbers, as follows:
B [1] = 2 * A [1]
B [2] = 3 * A [1] + 2 * A [2]
B [3] = 4 * A [1] + 3 * A [2] + 2 * A [3]
(... and so on)
I made the program, but my logic is wrong and I can not identify the error. Can someone help me? Here is the code I wrote.
#include <iostream>
using namespace std;
int main(){
int tamanho;
cout << "Qual o tamanho do vetor? ";
cin >> tamanho;
float vetorA[tamanho], vetorB[tamanho];
for (int i = 0; i < tamanho; i++){
cout<< "Digite o numero :";
cin >> vetorA[i];
}
for(int i = 0; i < tamanho; i++){
for(int j = 2; j <= tamanho + 1; j++){
vetorB[i] += j * vetorA[i];
}
}
int i = 0;
while(i < tamanho){
cout << "\nA["<< i << "] = " << vetorA[i] << "\t B[" << i << "] = " << vetorB[i];
i++;
}
}