0% found this document useful (0 votes)
9 views3 pages

Assignment 6

The document contains a C++ program that implements a distance vector routing algorithm. It prompts the user to enter the number of nodes and a distance matrix, then calculates and displays the shortest paths and next hops for each router. The output provides routing information for three routers based on the input distance matrix.
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)
9 views3 pages

Assignment 6

The document contains a C++ program that implements a distance vector routing algorithm. It prompts the user to enter the number of nodes and a distance matrix, then calculates and displays the shortest paths and next hops for each router. The output provides routing information for three routers based on the input distance matrix.
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/ 3

Name :- Maithili Kishor Narkhede

Div :- A
Roll No. :- COTA28

ASSIGNMENT NO:-6
PROGRAM:-

#include <iostream>

#include <stdio.h>

using namespace std;

struct node {

int dist[20];

int from[20];

}route[10];

int main()

int dm[20][20], no;

cout<<"Enter no of nodes:"<<endl;

cin>>no;

cout<<"Enter the distance matrix:"<<endl;

for (int i=0; i < no; i++)

for (int j = 0; j < no;j++)

cin>>dm[i][j];

dm[i][i]=0;

route[i].dist[j]=dm[i][j];

route[i].from[j]=j;

int flag;

do {
flag=0;

for (int i=0; i < no; i++)

for (int j = 0; j < no;j++)

for (int k=0; k< no; k++)

if((route[i].dist[j])>(route[i].dist[k]+route[k].dist[j]))

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

route[i].from[j]=k;

flag=1;

}while(flag);

for(int i=0;i<no;i++)

cout<<"Router info for router:"<<i+1<<endl;

cout<<"Dest\tNext Hop\tDist"<<endl;

for(int j=0;j<no;j++)

cout<<j+1<<"\t"<<route[i].from[j]+1<<"\t\t"<<route[i].dist[j]<<endl;

return 0;

}
OUTPUT:-
Enter no of nodes:

Enter the distance matrix:

013

102

320

Router info for router:1

Dest Next Hop Dist

1 1 0

2 2 1

3 3 3

Router info for router:2

Dest Next Hop Dist

1 1 1

2 2 0

3 3 2

Router info for router:3

Dest Next Hop Dist

1 1 3

2 2 2

3 3 0

You might also like