Write a C program to display Indegree and outdgree degree of each vertex.
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of vertices: ");
scanf("%d", &n);
int adj[n][n];
// Input adjacency matrix
printf("Enter adjacency matrix (%dx%d) (1 for edge, 0 for no edge):\n", n, n);
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
scanf("%d", &adj[i][j]);
}
}
printf("Vertex\tIndegree\tOutdegree\n");
for(i = 0; i < n; i++) {
int indegree = 0, outdegree = 0;
// Outdegree: count of 1s in row i
for(j = 0; j < n; j++)
outdegree += adj[i][j];
// Indegree: count of 1s in column i
for(j = 0; j < n; j++)
indegree += adj[j][i];
printf("%d\t%d\t\t%d\n", i + 1, indegree, outdegree);
}
return 0;
}
