Untitled

 avatar
unknown
plain_text
6 months ago
530 B
2
Indexable
and stores it as an adjacency matrix.*/

#include<stdio.h>

void printGraph(int adj[n][n])

{

int n;

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

printf("%d ",adj[i][j]);

}

printf("\n");

}

}

int main()

{

int s,d;

printf("No of Vertices");

scanf("%d",&n);

int adj[n][n];

for(int i=0;i<n;i++) for(int j=0;j<n;j++) adj[i][j]=0;

while(s!=-1 && d!=-1)

{

printf("enter an edge from node (0 to %d) to node (0 to %d):",n,n); scanf("%d%d", &s,&d);

adj[s][d]=1;

adj[d][s]=1;

}

printGraph(adj);

return 0;

}

OUTPUT
Editor is loading...
Leave a Comment