Excelente, muchas gracias. Un error tonto, a ponerse los anteojos...
Otro detalle, para obtener la DIAGONAL PRINCIPAL, la sección del código debe quedar así:
void Diag (int a[TAM][TAM], int n, int d[TAM])
{
cout<<"Te voy a dar la diagonal principal: \n\n";
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
d[i]=a[i][i]; //<---CORRECCIÓN
}
Hola. Quiero saber cómo hacer para que se imprima la CANTIDAD de ELEMENTOS NULOS de la matriz pero SÓLO LOS QUE ESTÁN ARRIBA (por encima, sobre) de LA DIAGONAL PRINCIPAL.
#include <iostream>
using namespace std;
const int TAM=4;
int main()
{
int nonul=0;
int c=0;
int M[TAM][TAM]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int i,j;
//---------------------------------EL ERROR ESTÁ AQUÍ:
for (int i=0; i<=TAM-2; i++)
for (int j=1; j<=TAM-1; j++)
if(M[i][j]==0)
{
c++;
}
cout<<"nulos:"<<c<<endl;
}