Untitled

 avatar
unknown
c_cpp
4 years ago
778 B
7
Indexable
#include<bits/stdc++.h>

using namespace std;

int main(){

//matrix of size 8*8 is made

int**am=new int*[8];

//all cells are initialised to 0 as initially no edges are there

for(int i=0;i<8;i++){

am[i]=new int[8];

for(int j=0;j<8;j++){

am[i][j]=0;

}

}

//edges are added in the form am[from][to]=1

am[0][1]=1;am[0][5]=1;

am[1][2]=1;

am[2][3]=1;

am[4][2]=1;am[4][3]=1;am[4][5]=1;

am[5][1]=1;

am[6][0]=1;am[6][1]=1;am[6][5]=1;am[6][7]=1;

am[7][0]=1;

//to rpint theadjacency matrix, outer loop iterates through all rows.

for(int i=0;i<8;i++){

//inner loopiterates through all columns

for(int j=0;j<8;j++){

cout<<am[i][j]<<" ";

}

//after one row is completes, a new line is started.

cout<<endl;

}

}
Editor is loading...