-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.c
54 lines (43 loc) · 1.04 KB
/
graph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
int n;
//function to find indegree
int indegree(int arr[][n], int m){
int count = 0;
for(int i=0; i<n; i++){
count += arr[m][i];
}
return count;
}
//function to find outdegree
int outdegree(int arr[][n], int m){
int count = 0;
for(int i=0; i<n; i++){
count += arr[i][m];
}
return count;
}
int main(void){
printf("Enter number of node - ");
scanf("%d", &n);
int arr[n][n];
printf("Enter Graph [in matrix form] - \n");
//creating graph
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
scanf("%d", &arr[i][j]);
}
}
printf("Graph is [in matrix form] - \n");
//printing graph
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
printf("%d ", arr[i][j]);
}
printf("\n");
}
int inD = indegree(arr, 1);
int outD = outdegree(arr, 1);
printf("INDEGREE is - %d.\n", inD);
printf("INDEGREE is - %d.\n", outD);
return 0;
}