-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph1.c
44 lines (39 loc) · 776 Bytes
/
Graph1.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
#include<stdio.h>
#include<stdlib.h>
int main()
{
int arr[5][5]={{0,1,1,1,0},
{1,0,1,0,1},
{1,1,0,1,1},
{1,0,1,0,1}};
int i,j;
int deg[5],sum=0;
char vc[]="ABCDE";
printf("adjancency Matrix : \n");
for( i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
for(i=0;i<4;i++){
int count =0;
for(j=0;j<4;j++){
if(arr[i][j] == 1)
{
count++;
}
deg[i]=count;
}
}
printf("degree of each node : \n");
for(i=0;i<4;i++)
{
printf("Vertices of %c Degree %d \n",vc[i],deg[i]);
sum=sum+deg[i];
}
printf("\nNumber of edges = %d",sum/2);
return 0;
}