#include<stdio.h>
#include<conio.h>
int a[10][10],n;
main()
{
int i,j,root;
printf("enter number of nodes \t");
scanf("%d",&n);
printf("enter adjacency matrix \t");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("enter connectivity of %d to %d is \n ",i,j);
scanf("%d",&a[i][j]);
}
printf("enter root node");
scanf("%d",&root);
adj(root);
}
adj(int k)
{
int i,j;
printf("\n adjacent nodes of the root of node %d is \n",k);
for(i=1;i<=n;i++)
if(a[k][i]==1||a[i][k]==1)
printf("%d\t",i);
printf("the remaining nodes \n");
for(i=1;i<=n;i++)
if((a[k][i]==0)&&(k!=i))
printf("%d",i);
}
#include<conio.h>
int a[10][10],n;
main()
{
int i,j,root;
printf("enter number of nodes \t");
scanf("%d",&n);
printf("enter adjacency matrix \t");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("enter connectivity of %d to %d is \n ",i,j);
scanf("%d",&a[i][j]);
}
printf("enter root node");
scanf("%d",&root);
adj(root);
}
adj(int k)
{
int i,j;
printf("\n adjacent nodes of the root of node %d is \n",k);
for(i=1;i<=n;i++)
if(a[k][i]==1||a[i][k]==1)
printf("%d\t",i);
printf("the remaining nodes \n");
for(i=1;i<=n;i++)
if((a[k][i]==0)&&(k!=i))
printf("%d",i);
}
No comments:
Post a Comment