#include<conio.h>
#include<stdio.h>
void main()
{
int distance[10][10],vector[10][2],delay[10];
int i,j,n,a,k;
char c[10]={'a','b','c','d','e','f','g','h','i','j'},adj[10],ch;
int m=0,p;
clrscr();
printf("Enter Number Of Nodes: ");
scanf("%d",&n);
fflush(stdin);
printf("Enter Distance Vector Node: ");
scanf("%c",&ch);
fflush(stdin);
printf("Enter Number Of Adjacent Nodes Of %c Node: ",ch);
scanf("%d",&a);
printf("Select Adjacent Nodes Of %c: \n",ch);
for(i=0;i<a;i++)
{
fflush(stdin);
printf("\nEnter: ");
scanf("%c",&adj[i]);
}
printf("\nDistance Matrix: \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<a;j++)
{
printf("Enter Weight For %c-%c : ",c[i],adj[j]);
scanf("%d",&distance[i][j]);
}
}
printf("\nEnter Delay Time For All Adjacent Nodes: ");
for(i=0;i<a;i++)
{
printf("\nEnter Delay Time For %c Node: ",adj[i]);
scanf("%d",&delay[i]);
}
printf("\n\nDistance Matrix For %c Node\n",ch);
for(i=0;i<n;i++)
{
for(j=0;j<a;j++)
printf("%4d",distance[i][j]);
printf("\n");
}
printf("\n\n");
for(i=0;i<a;i++)
printf("%4d",delay[i]);
for(i=0;i<n;i++)
{
m=distance[i][0]+delay[0];
p=1;
for(j=1;j<a;j++)
{
if(m>distance[i][j]+delay[j])
{
m=distance[i][j]+delay[j];
p=j+1;
}
}
vector[i][0]=m;
vector[i][1]=p;
}
printf("\n\nVector Matrix For %c Node \n",ch);
for(i=0;i<n;i++)
{
printf("%4d %4c",vector[i][0],adj[(vector[i][1]-1)]);
printf("\n");
}
getch();
}
/*
OUTPUT:-
Enter Number Of Nodes: 4
Enter Distance Vector Node: a
Enter Number Of Adjacent Nodes Of a Node: 2
Select Adjacent Nodes Of a:
Enter: b
Enter: d
Distance Matrix:
Enter Weight For a-b : 5
Enter Weight For a-d : 12
Enter Weight For b-b : 0
Enter Weight For b-d : 15
Enter Weight For c-b : 7
Enter Weight For c-d : 9
Enter Weight For d-b : 15
Enter Weight For d-d : 0
Enter Delay Time For All Adjacent Nodes:
Enter Delay Time For b Node: 7
Enter Delay Time For d Node: 9
Distance Matrix For a Node
5 12
0 15
7 9
15 0
7 9
Vector Matrix For a Node
12 b
7 b
14 b
9 d
*/
No comments:
Post a Comment