Graph-Incident Matrix, In-degree,Out-degree
Learn Theory-Graph Representations
int inc[50][50],nv,ne;
void read()
{ int i,j,e;
printf("Enter the Number of vertices\n");
scanf("%d",&nv);
printf("Enter the Number of edges\n");
scanf("%d",&ne);
// storing element from [1][1]
//assuming the vertices and edges are numbered 1 2..n and we will enter only the index
//use 1 for outgoing edges -1 for incoming edges 0 for no relation
for(int i=1;i<=nv;i++)
{
printf("Enter the details of edges incident to v%d \n",i);
for(j=1;j<=ne;j++)
{
scanf("%d",&e);
inc[i][j]=e;
}
}
}//end of read
void disp()
{
printf("Incident Matrix..\n");
for(int i=1;i<=nv;i++)
{
for(int j=1;j<=ne;j++)
printf("%5d",inc[i][j]);
printf("\n");
}
}
void indegree()
{ int vi,i,id=0;
printf("Enter the vertex index to compute indegree...\n");
scanf("%d",&vi);
for(i=1;i<=ne;i++)
if(inc[vi][i]==-1) id++;
printf("Indegree of vertex v%d=%d\n",vi,id);
}
void outdegree()
{ int vi,i,od=0;
printf("Enter the vertex index to compute outdegree..\n");
scanf("%d",&vi);
for(i=1;i<=ne;i++)
if(inc[vi][i]==1) od++;
printf("Outdegree of vertex v%d=%d\n",vi,od);
}
int main()
{
read();
disp();
indegree();
outdegree();
return 0;
}
"Your writing is exceptional! You have a talent for making even the most complicated topics feel accessible and enjoyable. I'm always eager to see what you'll share next—keep inspiring us with your amazing content!"
ReplyDelete