Shortest Path using Dijkstras Alogrithm

This program to calculate shortest routing path using Dijkstra’s algorithm. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4 #include<conio.h>

#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();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment