CN - WT Cse Lab Manual-52-56

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Department of CSE Computer Networks & Web Technologies Lab

6. Implement distance vector routing algorithm for obtaining routing tables at each node.
AIM:
Program:
#include <stdio.h>
int ja,ji,jh,jk;
void calc( );
int repa[20],repi[20],reph[20],repk[20],rsp[20];
char line[20];
int main( )
{
int i=0;
printf("Enter a delay time\n");
scanf("%d %d %d %d",&ja,&ji,&jh,&jk);
printf("Enter response time\n");
for(i=0;i<12;i++)
{
printf("Enter value \n");
scanf("%d %d %d %d",&repa[i],&repi[i],&reph[i],&repk[i]);
}
calc( );
printf("Least response\n");
for(i=0;i<12;i++)
{
printf("%d\t%c\n",rsp[i],line[i]);
}}
void calc( )
{
int i;
for(i=0;i<12;i++)
{

KMIT Page no:52


Department of CSE Computer Networks & Web Technologies Lab

repa[i]=repa[i]+ja;
repi[i]=repi[i]+ji;
reph[i]=reph[i]+jh;
repk[i]=repk[i]+jk;
}
for(i=0;i<12;i++)
{
if(i==9)
{
rsp[i]=0;
line[i]='J';
}
else
{
rsp[i]=min(repa[i],repi[i],reph[i],repk[i]);
if(rsp[i]==repa[i])
line[i]='A';
else if(rsp[i]==repi[i])
line[i]='I';
else if(rsp[i]==reph[i])
line[i]='H';
else
line[i]='K';
}
}
}
int min(int repa,intrepi,intreph,intrepk)
{
int i,j;
if(repa<repi)

KMIT Page no:53


Department of CSE Computer Networks & Web Technologies Lab

i=repa;
else
i=repi;
if(reph<repk)
j=reph;
else
j=reph;
if(i<j)
return i;
else
return j;
}
Output:
Enter a delay time
8
10
12
6
Enter response time
Enter value
0
24
20
21
Enter value
12
36
31
28
Enter value
25
18
19
36
Enter value
40
27
8
24

KMIT Page no:54


Department of CSE Computer Networks & Web Technologies Lab

Enter value
14
7
30
22
Enter value
23
20
19
40
Enter value
18
31
6
31
Enter value
17
20
0
19
Enter value
21
0
14
22
Enter value
9
11
7
10
Enter value
24
22
22
0
Enter value
29
33
9
9
Least response
8 A
20 A
28 I
20 H
17 I

KMIT Page no:55


Department of CSE Computer Networks & Web Technologies Lab

30 I
18 H
12 H
10 I
J
32 A
21 H

KMIT Page no:56

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy