-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphasMatrix2.cpp
68 lines (53 loc) · 1.02 KB
/
graphasMatrix2.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<iomanip>
using namespace std;
void printMatrix(int mat[][20],int n)
{
cout<<"\n ******** Graph as Adjacency Matrix ******* \n \n";
int i,j;
cout<<"\n\n"<<setw(4)<<"";
for(i = 1; i <=n; i++)
cout<<setw(3)<<"("<<i<<")";
cout<<"\n\n";
for(i = 1; i <= n; i++)
{
cout<<setw(3)<<"("<<i<<")";
for(j = 1; j <=n; j++)
{
cout<<setw(4)<<mat[i][j];
}
cout<<"\n\n";
}
}
int main()
{
// clrscr();
int n;
cout<<"Enter the number of vertices of the graph : \n" ;
cin>>n;
char a;
int matrix[20][20];
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
if(i!=j)
{
cout<<"Is edge "<<i<<" connected with edge "<<j<<" (y/n) \n";
cin>>a;
if(a=='Y'|| a=='y')
{
matrix[i][j] =1;
}
else
matrix[i][j] = 0;
matrix[j][i] = matrix[i][j];
}
else
{
matrix[i][j]=0;
}
}
}
printMatrix(matrix,n);
}