Notes
Notes - notes.io |
{
int option;
clrscr();
do
{ printf("n A Program to represent a Graph by using an ");
printf("Adjacency Matrix method n ");
printf("n 1. Directed Graph ");
printf("n 2. Un-Directed Graph ");
printf("n 3. Exit ");
printf("nn Select a proper option : ");
scanf("%d", &option);
switch(option)
{
case 1 : dir_graph();
break;
case 2 : undir_graph();
break;
case 3 : exit(0);
} // switch
}while(1);
} // main
int dir_graph()
{
int adj_mat[50][50];
int n;
int in_deg, out_deg, i, j;
printf("n How Many Vertices ? : ");
scanf("%d", &n);
read_graph (adj_mat, n);
printf("n Vertex t In_Degree t Out_Degree t Total_Degree ");
for (i = 1; i < = n ; i++ )
{
in_deg = out_deg = 0;
for ( j = 1 ; j <= n ; j++ )
{
if ( adj_mat[j][i] == 1 )
in_deg++;
} // for
for ( j = 1 ; j <= n ; j++ )
if (adj_mat[i][j] == 1 )
out_deg++;
printf("nn %5dttt%dtt%dtt%dnn",i,in_deg,out_deg,in_deg+out_deg);
} // for
return;
} // dir_graph
int undir_graph()
{
int adj_mat[50][50];
int deg, i, j, n;
printf("n How Many Vertices ? : ");
scanf("%d", &n);
read_graph(adj_mat, n);
printf("n Vertex t Degree ");
for ( i = 1 ; i <= n ; i++ )
{
deg = 0;
for ( j = 1 ; j <= n ; j++ )
if ( adj_mat[i][j] == 1)
deg++;
printf("nn %5d tt %dnn", i, deg);
} // for
return;
} // undir_graph
int read_graph ( int adj_mat[50][50], int n )
{
int i, j;
char reply;
for ( i = 1 ; i <= n ; i++ )
{
for ( j = 1 ; j <= n ; j++ )
{
if ( i == j )
{
adj_mat[i][j] = 0;
continue;
} // if
printf("n Vertices %d & %d are Adjacent ? (Y/N) :",i,j);
flushall();
scanf("%c", &reply);
if ( reply == 'y' || reply == 'Y' )
adj_mat[i][j] = 1;
else
adj_mat[i][j] = 0;
} // for
} // for
return;
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team