## Pages

### Adjacency Matrix C Program Data Structure

This Program is for Adjacency Matrix in C , and is a part  of Mumbai University MCA Colleges Data Structures C program MCA Sem 2

#include<stdio.h>
#include<conio.h>
#define max 20
int n;
main()
{
int choice;
int node,origin,destin;
clrscr();
printf("================== ADJACENCY MATRIX =======================\n\n");
create_graph();
while(1)
{
printf("1.Insert a node\n");
printf("2.Delete a node\n");
printf("3.Dispaly\n");
printf("4.Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert_node();
break;
case 2:
printf("Enter a node to be deleted : ");
fflush(stdin);
scanf("%d",&node);
delete_node(node);
break;
case 3:
display();
break;
case 4:
exit();
default:
printf("Wrong choice\n");
break;
}
}
getch();
}

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
}
}

display()
{
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("\n");
}
}

insert_node()
{
int i;
n++;
printf("The inserted node is %d \n",n);
for(i=1;i<=n;i++)
{
}
}

delete_node(char u)
{
int i,j;
if(n==0)
{
printf("Graph is empty\n");
return;
}
if( u>n )
{
printf("This node is not present in the graph\n");
return;
}
for(i=u;i<=n-1;i++)
for(j=1;j<=n;j++)
{