0% found this document useful (0 votes)
23 views2 pages

Network Routing Algorithm

The document contains a C program that implements the Distance Vector Routing algorithm. It prompts the user to input the number of nodes and a cost matrix, then calculates the shortest paths between nodes. Finally, it outputs the routing information for each router, including the distance and the next hop node.

Uploaded by

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

Network Routing Algorithm

The document contains a C program that implements the Distance Vector Routing algorithm. It prompts the user to input the number of nodes and a cost matrix, then calculates the shortest paths between nodes. Finally, it outputs the routing information for each router, including the distance and the next hop node.

Uploaded by

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

PROGRAM

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
struct node
{
​ unsigned distance[20];
​ unsigned fromnod[20];
}n[10];
void main()
{
int costmatrix[20][20];
int node,i,j,k,t,count=0;
printf("\nEnter the number of nodes:\t");
scanf("%d",&node);
printf("\nEnter the costmatrix:\t");
for(i=0;i<node;i++)
{
for(j=0;j<node;j++)
{
scanf("%d",&costmatrix[i][j]);
costmatrix[i][i]=0;
n[i].distance[j]=costmatrix[i][j];
n[i].fromnod[j]=j;
}
}

do
{
count=0;
for(i=0;i<node;i++)
{
for(j=0;j<node;j++)
{
for(k=0;k<node;k++)
{
t=costmatrix[i][k]+n[k].distance[j];
if(n[i].distance[j]>t)
{
n[i].distance[j]=t;
n[i].fromnod[j]=k;
count++;
}
}
}
}
}while(count!=0);

for(i=0;i<node;i++)
{
printf("\nFor router %d:",i+1);
for(j=0;j<node;j++)
{
printf("\nNode %d through %d distance %d ",j+1,n[i].fromnod[j]+1,n[i].distance[j]);
}
}
printf("\n");
}

OUTPUT

You might also like