distance vector routing


#include<stdio.h>
#include<conio.h>
#define MAX 10
int n,i,m[MAX][MAX],a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];
int rt,count,k,j,l,d[MAX];
main()
{
clrscr();
  int x;
printf("enter numberof nodes \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the connectivity of %d",i);
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
}
printf("enter the root node \n");
scanf("%d",&rt);
printf("\n the adjacent node of root node %d is",rt);
count=0;
for(j=1;j<=n;j++)
{
if((a[rt][j]==1)||(a[j][rt]==1))
{
printf("%d \t",j);
d[count]=j;
count=count+1;
}
}
d[count]=0;
for(i=0;i<count;i++)
{
k=d[i];
printf("enter the delay matrix of %d",k);
for(j=1;j<=n;j++)
scanf("%d",&b[k][j]);
printf("enter the delay from %d source to its adjacent node %d",rt,k);
scanf("%d",&c[rt][k]);
}
i=0;
k=d[i];
l=d[i+1];
for(j=1;j<=n;j++)
{
if((b[k][j]+c[rt][k])<=(b[l][j]+c[rt][l]))
m[rt][j]=b[k][j]+c[rt][k];
else
m[rt][j]=b[l][j]+c[rt][l];
}
k=2;
while(d[k]!=0)
{
x=d[k];
for(l=1;l<=n;l++)
{
if(m[rt][l]>=c[rt][x]+b[x][l])
{
m[rt][l]=c[rt][x]+b[x][l];
k=k+1;
}
}
}
printf("the delay vector of root node is \n");
for(j=1;j<=n;j++)
{
if(rt==j)
printf("0");
else
printf("%d",m[rt][j]);
}
}

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams