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

Program

The provided C program implements a distance vector routing algorithm to calculate the shortest paths between nodes in a network. It prompts the user to enter the number of nodes and a cost matrix, then computes the shortest distances and the next hop for each node. Finally, it displays the routing information for each router, including the distance to each node and the next node to reach it.

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Program

The provided C program implements a distance vector routing algorithm to calculate the shortest paths between nodes in a network. It prompts the user to enter the number of nodes and a cost matrix, then computes the shortest distances and the next hop for each node. Finally, it displays the routing information for each router, including the distance to each node and the next node to reach it.

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 DOCX, 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