0% found this document useful (0 votes)
7 views4 pages

Distance Vector Routing Program in C

The document presents a C program that implements a distance vector routing algorithm. It allows the user to input a distance matrix for a specified number of nodes and computes the shortest paths between them. The program also enables the user to update the cost of a specific route and recalculates the distances accordingly.

Uploaded by

moral.work19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Distance Vector Routing Program in C

The document presents a C program that implements a distance vector routing algorithm. It allows the user to input a distance matrix for a specified number of nodes and computes the shortest paths between them. The program also enables the user to update the cost of a specific route and recalculates the distances accordingly.

Uploaded by

moral.work19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Distance vector routing program in C

#include<stdio.h>

int dist[50][50],temp[50][50],n,i,j,k,x;

void dvr();

int main()

printf("\nEnter the number of nodes : ");

scanf("%d",&n);

printf("\nEnter the distance matrix :\n");

for(i=0;i<n;i++)

for(j=0;j<n;j++)

scanf("%d",&dist[i][j]);

dist[i][i]=0;

temp[i][j]=j;

printf("\n");

dvr();

printf("enter value of i &j:");

scanf("%d",&i);

scanf("%d",&j);
printf("enter the new cost");

scanf("%d",&x);

dist[i][j]=x;

printf("After update\n\n");

dvr();

return 0;

void dvr()

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

for (k = 0; k < n; k++)

if (dist[i][k] + dist[k][j] < dist[i][j])

dist[i][j] = dist[i][k] + dist[k][j];

temp[i][j] = k;

for(i=0;i<n;i++)

printf("\n\nState value for router %d is \n",i+1);

for(j=0;j<n;j++)

printf("\t\nnode %d via %d Distance%d",j+1,temp[i][j]+1,dist[i][j]);

printf("\n\n");
}

OUTPUT:

Enter the number of nodes : 4

Enter the distance matrix :


0
12
9
16

20
0
18
4

15
8
0
32

41
24
51
0

State value for router 1 is

node 1 via 1 Distance0


node 2 via 2 Distance12
node 3 via 3 Distance9
node 4 via 4 Distance16

State value for router 2 is

node 1 via 1 Distance20


node 2 via 2 Distance0
node 3 via 3 Distance18
node 4 via 4 Distance4

State value for router 3 is

node 1 via 1 Distance15


node 2 via 2 Distance8
node 3 via 3 Distance0
node 4 via 2 Distance12

State value for router 4 is


node 1 via 1 Distance41
node 2 via 2 Distance24
node 3 via 2 Distance42
node 4 via 4 Distance0

enter value of i &j:


1
3
enter the new cost
68
After update

State value for router 1 is

node 1 via 1 Distance0


node 2 via 2 Distance12
node 3 via 3 Distance9
node 4 via 4 Distance16

State value for router 2 is

node 1 via 1 Distance20


node 2 via 2 Distance0
node 3 via 3 Distance18
node 4 via 3 Distance30

State value for router 3 is

node 1 via 1 Distance15


node 2 via 2 Distance8
node 3 via 3 Distance0
node 4 via 2 Distance12

State value for router 4 is

node 1 via 1 Distance41


node 2 via 2 Distance24
node 3 via 2 Distance42
node 4 via 4 Distance0
--------------------------------

You might also like