1. Asta e varaianta in care folosesti o matrice si poate pare mai usor:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n, E[21][21], c, g;
cin>>n;
c=n;
for(int i=1;i<=n;i++)
{
c--, g=c;
for(int j=1;j<=n;j++)
{
if(i+j==n+1) E[i][j]=0;
else if(i+j<n+1) E[i][j]=g;
else E[i][j]=abs(g);
g--;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cout<<E[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
2. Asta e varianta fara matrice, dar mai rapida:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n, c, g;
cin>>n;
c=n;
for(int i=1;i<=n;i++) {
c--, g=c;
for(int j=1;j<=n;j++) {
if(i+j==n+1) cout<<0<<" ";
else if(i+j<n+1) cout<<g<<" ";
else cout<<abs(g)<<" ";
g--;
}
cout<<"\n";
}
return 0;
}
Le ai si in notepad.