CN FILE 2
CN FILE 2
for(i=0;i<n;i++)
{
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
printf("\t\nnode %d via %d Distance%d",j+1,temp[i][j]+1,dist[i][j]);
}
printf("\n\n");
OUTPUT:
Enter the number of nodes : 4
Enter the distance matrix :
0
12
9
16
15
8
0
32
41
24
51
0
State value for router 1 is
#include <stdio.h>
#include <stdlib.h>
int graph[MAX][MAX];
int visited[MAX];
int nodes;
int main() {
int edges;
printf("Enter number of nodes: ");
scanf("%d", &nodes);
int source;
printf("Enter source node to start flooding: ");
scanf("%d", &source);
printf("\nFlooding started:\n");
flood(source, -1);
return 0;
}
OUTPUT:
Enter number of nodes: 4
Enter number of edges: 4
Enter edges (format: source destination):
01
02
13
23
Enter source node to start flooding: 0
int graph[MAX][MAX];
int distance[MAX];
int visited[MAX];
int parent[MAX];
int nodes;
distance[start] = 0;
visited[u] = 1;
void printPath(int j) {
if (parent[j] == -1)
return;
printPath(parent[j]);
printf(" -> %d", j);
}
int main() {
int edges;
printf("Enter number of nodes: ");
scanf("%d", &nodes);
return 0;
}