Solution:
#include<stdio.h>
#include<stdlib.h>
int n,g[10][10];
void inoutdegree()
{
int i,j,id=0,od=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
od+=g[i][j];
id+=g[j][i];
}
printf("v%d indegree =%d \t Outdegree= %d\n",i,id,od);
}
}
int main()
{
int i,j,cnt=0;
printf("How many vertices:\n");
scanf("%d",&n);
printf("Enter matrix elements:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&g[i][j]);
}
}
printf("\nAdjacency matrix Is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(g[i][j]!=g[j][i])
cnt++;
printf("%d\t",g[i][j]);
}
printf("\n");
}
if(cnt!=0)
{
printf("\nGiven graph is Directed\n\n");
inoutdegree();
}
else
{
printf("Graph is undirected\n\n");
}
return 0;
}
0 Comments