fork download
  1. //
  2. // main.cpp
  3. // Adjacency Matrix
  4. //
  5. // Created by Himanshu on 26/11/22.
  6. //
  7.  
  8. #include <iostream>
  9. #include <vector>
  10. #include <cmath>
  11. #include <climits>
  12. #define N 5
  13. using namespace std;
  14.  
  15. //N = number of nodes in graph
  16. void printAdjacencyMatrix(int G[][N]) {
  17.  
  18. for (int i=0; i<N; i++) {
  19. for (int j=0; j<N; j++) {
  20. cout<<G[i][j]<<" ";
  21. }
  22. cout<<endl;
  23. }
  24. }
  25.  
  26. int main() {
  27. int G[N][N] = {{0, 1, 0, 0, 0},
  28. {1, 0, 0, 1, 0},
  29. {0, 0, 0, 1, 1},
  30. {0, 1, 1, 0, 1},
  31. {0, 0, 1, 1, 0}};
  32.  
  33.  
  34. cout<<"Graph G (Adjacency Matrix):"<<endl;
  35. printAdjacencyMatrix(G);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
Graph G (Adjacency Matrix):
0 1 0 0 0 
1 0 0 1 0 
0 0 0 1 1 
0 1 1 0 1 
0 0 1 1 0