Created
August 6, 2019 13:06
-
-
Save harshityadav95/6e84ccf1eebb7d393db9d2ee72925112 to your computer and use it in GitHub Desktop.
Border Gateway Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
int main() | |
{ | |
int n; | |
int i, j, k; | |
int a[10][10], b[10][10]; | |
printf("\n Enter the number of nodes:"); | |
scanf("%d", &n); | |
for (i = 0; i < n; i++) | |
{ | |
for (j = 0; j < n; j++) | |
{ | |
printf("\n Enter the distance between the host %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[i][k] + a[k][j]) | |
{ | |
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 The output matrix:\n"); | |
for (i = 0; i < n; i++) | |
{ | |
for (j = 0; j < n; j++) | |
{ | |
printf("%d\t", b[i][j]); | |
} | |
printf("\n"); | |
} | |
getch(); | |
} | |
#include <stdio.h> | |
#include <conio.h> | |
int main() | |
{ | |
int n; | |
int i, j, k; | |
int a[10][10], b[10][10]; | |
printf("\n Enter the number of nodes:"); | |
scanf("%d", &n); | |
for (i = 0; i < n; i++) | |
{ | |
for (j = 0; j < n; j++) | |
{ | |
printf("\n Enter the distance between the host %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[i][k] + a[k][j]) | |
{ | |
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 The output matrix:\n"); | |
for (i = 0; i < n; i++) | |
{ | |
for (j = 0; j < n; j++) | |
{ | |
printf("%d\t", b[i][j]); | |
} | |
printf("\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment