Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main()
- {
- int n,i,j,k;
- printf("Enter no of nodes in subnet:");
- scanf("%d",&n);
- int a[n][n];
- struct rt
- {
- int rout[n];
- };
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- a[i][j]=0;
- }
- }
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- if(i==j)
- a[i][j]=0;
- else
- {
- if(i>j)
- {
- a[i][j]=a[j][i];
- }
- else
- {
- printf("path from %d to %d:",i,j);
- scanf("%d",&a[i][j]);
- a[j][i]=a[i][j];
- }
- }
- }
- }
- int node,adj[n],m=0;
- printf("enter the node for which routing table is to be calculated:");
- scanf("%d",&node);
- for(i=0;i<n;i++)
- {
- if(a[node][i]!=0)
- {
- adj[m++]=i;
- }
- }
- struct rt tables[m];
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- printf("enter the delay to go from %d to %d:",j,adj[i]);
- scanf("%d",&tables[i].rout[j]);
- }
- }
- int delays[m];
- for(i=0;i<m;i++)
- {
- printf("enter the delay from %d to %d:",node,adj[i]);
- scanf("%d",&delays[i]);
- }
- int rrtable[n][2];
- for(i=0;i<n;i++)
- {
- int min=5000,temp=0,in;
- if(i==node)
- {
- rrtable[i][0]=0;
- rrtable[i][1]=-1;
- }
- else
- {
- for(k=0;k<m;k++)
- {
- temp=tables[k].rout[i]+delays[k];
- if(temp<min)
- {
- min=temp;
- in=adj[k];
- }
- }
- rrtable[i][0]=min;
- rrtable[i][1]=in;
- }
- }
- printf("TO\tnode%d\tintermediate router\n",node);
- for(i=0;i<n;i++)
- printf("%d\t%d\t%d\n",i,rrtable[i][0],rrtable[i][1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement