Anna University Results November - December 2011 available with your GPA only for Credit System

Exam Results 2012

Exam Results 2012 Inspirational Quotes

Saturday, September 18, 2010

Implementation of Distance Vector Routing



/* Implementation of Distance Vector Routing */

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int i,j,k,n,a[10][10],b[10][10],src,s,d;
char ch;
clrscr();
printf("\n Enter the number of nodes = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
a[i][j]=0;
else
{
printf("\n Enter the distance between host : %d and %d ==> ",i,j);
scanf("%d",&a[i][j]);
}
}
}
printf("\n ");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n ");
}
do
{
printf("\n Enter the node to display the routing table : ");
scanf("%d",&src);
for(j=1;j<=n;j++)
{
if(src!=j)
{
if(a[src][j]!=0)
printf("\n The shortest path from %d to %d = %d \n",src,j,a[src][j]);
else
printf("\n There is no path from %d to %d \n",src,j);
}
}
printf("\n Do u want to continue(y/n) : ");
scanf("%s",&ch);
}while(ch!='n');
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}

OUT PUT :

                                                                                                SHOWS  A  SUBNET

Enter the number of nodes = 6

Enter the distance between host : 1 and 2 ==> 2

Enter the distance between host : 1 and 3 ==> 5

Enter the distance between host : 1 and 4 ==> 1

Enter the distance between host : 1 and 5 ==> 2

Enter the distance between host : 1 and 6 ==> 10

Enter the distance between host : 2 and 1 ==> 2

Enter the distance between host : 2 and 3 ==> 3

Enter the distance between host : 2 and 4 ==> 2

Enter the distance between host : 2 and 5 ==> 3

Enter the distance between host : 2 and 6 ==> 8

Enter the distance between host : 3 and 1 ==> 5

Enter the distance between host : 3 and 2 ==> 3

Enter the distance between host : 3 and 4 ==> 3

Enter the distance between host : 3 and 5 ==> 1

Enter the distance between host : 3 and 6 ==> 5

Enter the distance between host : 4 and 1 ==> 1

Enter the distance between host : 4 and 2 ==> 2

Enter the distance between host : 4 and 3 ==> 3

Enter the distance between host : 4 and 5 ==> 1

Enter the distance between host : 4 and 6 ==> 3



Enter the distance between host : 5 and 1 ==> 6

Enter the distance between host : 5 and 2 ==> 4

Enter the distance between host : 5 and 3 ==> 1

Enter the distance between host : 5 and 4 ==> 1

Enter the distance between host : 5 and 6 ==> 2

Enter the distance between host : 6 and 1 ==> 10

Enter the distance between host : 6 and 2 ==> 8

Enter the distance between host : 6 and 3 ==> 5

Enter the distance between host : 6 and 4 ==> 3

Enter the distance between host : 6 and 5 ==> 2

ROUTING TABLE :


1
2
3
4
5
6
1
0
2
5
1
2
10
2
2
0
3
2
3
8
3
5
3
0
3
1
5
4
1
2
3
0
1
3
5
6
4
1
1
0
2
6
10
8
5
3
2
0

Enter the node to display the routing table : 2
The shortest path from 2 to 1 = 2
The shortest path from 2 to 3 = 3
The shortest path from 2 to 4 = 2
The shortest path from 2 to 5 = 3
The shortest path from 2 to 6 = 8
Do u want to continue (y/n) : n


ROUTING TABLE FOR 2 :


1
2
3
4
5
6
1
0
2
3
1
2
4
2
2
0
3
2
3
5
3
3
3
0
2
1
3
4
1
2
2
0
1
3
5
2
3
1
1
0
2
6
4
5
3
3
2
0


No comments: