In a graph when a particular edge having both start and end vertices in it known as self loop.
This program will detect the self loop in a given graph.
This program will detect the self loop in a given graph.
#include<stdio.h> #include<conio.h> void main() { int i,j; int count2; int m,n,a[10][10]; clrscr(); printf("\n @@@ Enter the no of edge and vertice @@@ \n-> "); scanf ("%d%d",&m,&n); printf ("\n Enter the adjacency matrix : \n"); for (i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } total=0; for (i=0;i<m;i++) { count=0; for(j=0;j<m;j++) { if ( a[i][j]==1 && i!=j) { count=count+1; } else if(i==j && a[i][j]==1) { count=count+2; printf ("\n>>>vertex %d contain self loop in a graph",i+1); } } } getch(); }
No comments:
Write comments