-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathungericht_matrix.c
More file actions
56 lines (46 loc) · 1.02 KB
/
ungericht_matrix.c
File metadata and controls
56 lines (46 loc) · 1.02 KB
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
55
56
#include <stdio.h>
#include <stdlib.h>
#define MAX 20
int adj[MAX][MAX];
int n; // Denotes number of nodes in the graph
void create_graph()
{
int i,max_edges,origin,destin;
printf("Enter number of nodes : ");
scanf("%d",&n);
max_edges=n*(n-1);
for(i=1;i<=max_edges;i++)
{
printf("Enter edge %d( 0 0 to quit ) : ",i);
scanf("%d %d",&origin,&destin);
if((origin==0) && (destin==0))
break;
if( origin > n || destin > n || origin<=0 || destin<=0)
{
printf("Invalid edge!\n");
i--;
}
else
{
adj[origin][destin]=1;
}
}// End of for
}// End of create_graph()
void display()
{
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%4d",adj[i][j]);
printf("\n");
}
}// End of display()
int main()
{
int i,v,choice;
create_graph();
printf("Adjacency Matrix\n");
display();
return 0;
}// End of main()