#include<stdio.h>
int a[10][10],s[10],n;
void read_adjacency_matrix(int a[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
}
void dfs(int u)
{
int v;
s[u]=1;
printf("%d\t",u);
for(v=0;v<n;v++)
{
if(a[u][v]==1 && s[v]==0)
dfs(v);
}
}
void main()
{
int i,source;
scanf("%d",&n);
read_adjacency_matrix(a,n);
for(source=0;source<n;source++)
{
for(i=0;i<n;i++)
{
s[i]=0;
}
printf("\n the nodes reachable from %d :",source);
dfs(source);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: