This program to calculate shortest routing path using Dijkstra’s algorithm.
#include<stdio.h>
void main()
{
int addj[10][10];
int n, i, j, k, src, des;
clrscr();
printf("How many vertices are there : ");
scanf("%d",&n);
printf("\nEnter values of matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&addj[i][j]);
}
}
printf("\nEnter source node: ");
scanf("%d", &src);
printf("\nEnter destination node: ");
scanf("%d", &des);
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(addj[i][j] > addj[i][k]+addj[k][j])
{
addj[i][j]=addj[i][k]+addj[k][j];
}
}
}
}
printf(“\n\n”);
printf("Shortest path matrix....");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d\t",addj[i][j]);
}
}
printf("\n\nThe cost of shortest path from %d to %d is %d", src,des,addj[src-1][des-1]);
getch();
}
#include<stdio.h>
void main()
{
int addj[10][10];
int n, i, j, k, src, des;
clrscr();
printf("How many vertices are there : ");
scanf("%d",&n);
printf("\nEnter values of matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&addj[i][j]);
}
}
printf("\nEnter source node: ");
scanf("%d", &src);
printf("\nEnter destination node: ");
scanf("%d", &des);
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(addj[i][j] > addj[i][k]+addj[k][j])
{
addj[i][j]=addj[i][k]+addj[k][j];
}
}
}
}
printf(“\n\n”);
printf("Shortest path matrix....");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d\t",addj[i][j]);
}
}
printf("\n\nThe cost of shortest path from %d to %d is %d", src,des,addj[src-1][des-1]);
getch();
}