Răspuns :
Nu uita ca in informatica vectorii incep de la indicele 0, si nu 1!!!!!
Problema 1:
#include <iostream>
using namespace std;
int main() {
int nLinii;
cout << "Numarul de linii al matricilor: " << endl;
cin >> nLinii;
int nColoane;
cout << "Numarul de coloane al matricilor: " << endl;
cin >> nColoane;
// matricea A
cout << "Citire matricea A: " << endl;
double A[nLinii][nColoane];
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " [ENTER dupa fiecare valore]: " << endl;
for (int j = 0; j < nColoane; j++) {
cin >> A[i][j];
}
}
cout << "Citire matricea B: " << endl;
double B[nLinii][nColoane];
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " [ENTER dupa fiecare valore]: " << endl;
for (int j = 0; j < nColoane; j++) {
cin >> B[i][j];
}
}
// Afisarea matricii A:
cout << endl << " Matricea A: " << endl;
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " : ";
for (int j = 0; j < nColoane; j++) {
cout << A[i][j] << " ";
}
cout << endl;
}
// Afisarea matricii B:
cout << endl << " Matricea B: " << endl;
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " : ";
for (int j = 0; j < nColoane; j++) {
cout << B[i][j] << " ";
}
cout << endl;
}
// A + B
cout << endl << " Matricea A + B: " << endl;
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " : ";
for (int j = 0; j < nColoane; j++) {
double suma = A[i][j] + B[i][j];
cout << suma << " ";
}
cout << endl;
}
// A - B
cout << endl << " Matricea A - B: " << endl;
for (int i = 0; i < nLinii; i++) {
cout << "Linia " << (i+1) << " : ";
for (int j = 0; j < nColoane; j++) {
double diferenta = A[i][j] - B[i][j];
cout << diferenta << " ";
}
cout << endl;
}
return 0;
}
-----------------------------------------------------------------------
Problema 2:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Numarul de elemente de citit: n = ";
cin >> n;
// Sirul t1
cout << "t1 [ENTER dupa fiecare valoare]: " << endl;
int t1[n];
for (int i = 0; i < n; i++) {
cin >> t1[i];
}
// determinarea lui t2: t1 de la coada la cap
int t2[n];
for (int i = 0; i < n; i++) {
t2[i] = t1[n - i - 1];
}
cout << "t2: " << endl;
for (int i = 0; i < n; i++) {
cout << t2[i] << " ";
}
return 0;
}