Răspuns:
#include <iostream>
using namespace std;
int n, aux;
int main()
{
cout << "Dati un numar natural: n = ";
cin >> n;
for(int i = 1; i < n; i++){
for(int j = 1; j < n; j++){
aux = i*(i+1)/2 + j*(j+1)/2;
if(aux == n){
cout << endl << n << " - poate fi scris ca suma de 2 nr triunghiulare";
cout << endl << n << " = " << i*(i+1)/2 << " + " << j*(j+1)/2;
cout << endl << endl;
exit(1);
}
}
}
cout << endl << n << " - nu poate fi scris ca suma de 2 numere triunghiulare";
cout << endl << endl;
return 0;
}