Skip to content

Instantly share code, notes, and snippets.

@sudikrt
Created August 4, 2017 18:27
Show Gist options
  • Save sudikrt/6ef2ba61997fe7f82cf947025075a1a2 to your computer and use it in GitHub Desktop.
Save sudikrt/6ef2ba61997fe7f82cf947025075a1a2 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<conio.h>
int a[10][10],count=0;visited[10],n;
void dfs(int v)
{
int i;
visited[v]=1;
for(i=0;i<n;i++)
{
if(a[v][i]&&!visited[i]){
printf("%d",i+1);
dfs(i);
}
}
}
main()
{
int i,j;
printf("Enter the number of vertices\n");
scanf("%d",&n);
printf("Enter the adjacency matrix\n");
for(i=0;i<n;i++)
visited[i]=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
printf("%d",1);
for(i=0;i<n;i++)
{
if(visited[i]==0)
count++;
dfs(0);
}
if(count==1)
printf("Connected");
else
printf("Not. . .Connn.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment