4
I have a problem with the following statement:
Given a vector A with n real numbers, obtain 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 did the program, but my logic is wrong and I can’t identify the error. Can anyone help me? Follow 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++;
}
}
Note: The program runs without build errors. The error is in logic!
– lys
No need to put
RESOLVIDO
, this is indicated otherwise, with an accepted answer. How and why to accept an answer? and tour– rray
Thanks for the tip!
– lys