C Program / Source Code For The Distance Vector Routing Algorithm Using Bellman Ford's Algorithm
C Program / Source Code For The Distance Vector Routing Algorithm Using Bellman Ford's Algorithm
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d
",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
/*
A sample run of the program works as:Enter the number of nodes :
3
Enter the cost matrix :
0 2 7
2 0 1
7 1 0
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
*/
>>>>>>>>>>>>>>>>>>>
/*************************************************************************************/
/* C Program to implement link state routing.*/
/* <span id="IL_AD2" class="IL_AD">Download</span> more programs at http://sourcecode4u.com/ */
/*************************************************************************************/
#include<stdio.h>
main()
{
int n,a[10][10],i,j,k;
printf("\n ENTER THE NO.OF NODES: ");
scanf("%d",&n);
printf("\n ENTER THE MATRIX ELEMENTS: ");
for(i=0;i<n;i++)
{
printf("\nENTER THE DISTANCE FOR NODE:%d\n",i+1);
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
printf("THE LINK STATE STATE PACKETS FOR NODE:%d\n",i+1);
printf("\n NODE\tDISTANCE\n");
for(j=0;j<n;j++)
{
if(a[i][j]!=0&&a[i][j]!=-1)
{
printf("%d\t%d\n",j+1,a[i][j]);
}
}
printf("\n\n");
}
Out Put