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("

Enter values of matrix:

");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

scanf("%d",&addj[i][j]);

}

}

printf("

Enter source node: ");

scanf("%d", &src);





printf("

Enter 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(“



”);

printf("Shortest path matrix....");

for(i=0;i<n;i++)

{

printf("

");

for(j=0;j<n;j++)

{

printf("%d\t",addj[i][j]);

}

}





printf("



The cost of shortest path from %d to %d is %d", src,des,addj[src-1][des-1]);

getch();

}



