Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter




C Program for creation of adjacency matrix


Posted Date: 24 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: ashish singh       Member Level: Diamond
Rating:     Points: 2



/* Program for creation of adjacency matrix */
#include
#define max 20

int adj[max][max]; /*Adjacency matrix */
int n; /* Denotes number of nodes in the graph */
main()
{
int max_edges,i,j,origin,destin;
char graph_type;

printf("Enter number of nodes : ");
scanf("%d",&n);
printf("Enter type of graph, directed or undirected (d/u) : ");
fflush(stdin);
scanf("%c",&graph_type);

if(graph_type=='u')
max_edges=n*(n-1)/2;
else
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;
if( graph_type=='u')
adj[destin][origin]=1;
}
}/*End of for*/

printf("The adjacency matrix is :\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%4d",adj[i][j]);
printf("\n");
}
}/*End of main()*/




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: C Program for addition and deletion of nodes and edges in a graph
Previous Resource: C Program of shortest path between two node in graph using Djikstra algorithm
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.