Translate

Monday, October 8, 2012

ME NETWORKS LAB-->SIMULATION OF ROUTING PROTOCOL


SIMULATION OF ROUTING PROTOCOL

(OPEN SHORTEST PATH PROTOCOL)

  

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n,j,k,a[10][10],b[10][10];

clrscr();

printf("enter no of nodes");

scanf("%d",&n);

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

{

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

{

printf("enter distance  between nodes %d %d : ",i+1,j+1);

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

}

}

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

{

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

printf("%d\t ",a[i][j]);

printf("\n");

}

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

{

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

{

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

{

if(a[i][j]>a[k][j]+a[i][k])

 

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

}}}

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

{

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

{

b[i][j]=a[i][j];

if(i==j)

 b[i][j]=0;

 }

 }

printf("\n output matrix\n");

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

{

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

printf("%d\t ",b[i][j]);

printf("\n");

}

getch();

}

 

OUTPUT:

 

Enter no of nodes: 3

Enter distance  between nodes 1 and  1 : 2

Enter distance  between nodes 1  and  2 : 3

Enter distance  between nodes 1 and  3 : 5

Enter distance  between nodes 2 and  1 : 4

Enter distance  between nodes 2  and  2 : 1

Enter distance  between nodes 2  and  3 : 6

Enter distance  between nodes 3  and  1 : 2

Enter distance  between nodes 3  and  2 : 4

Enter distance  between nodes 3  and  3 : 5

2        3       5

4        1       6

2        4       5

 

 Output matrix

0        3       5

4        0       6

2        4       0

 

1 comment:

  1. will u xplain the output .... becoz,the output was simple... form zeros in diagonal....

    wat was thw concept behind it? why should we convert the diagonal as zeros....

    Awaiting for ur reply...

    ReplyDelete